<?php
/**
 * @Author: king
 * @Date:   2019-02-17 19:50:25
 * @Last Modified by:   king
 * @Last Modified time: 2019-04-06 20:55:42
 */
namespace App\Tools\Astrolog;

use App\Models\Api\MonthFortune;
use App\Models\Api\YearFortune;
use App\Http\Controllers\Api\v1\Everyday\LuckdisastersController;
use App\Tools\HoroscopeData;
use App\Tools\Astrolog\CaclByTopic;
use App\Tools\Astrolog\Astrolog;

/**
 * 运势变化
 * Class FortunesChange
 * @package App\Tools\Astrolog\Astrolog
 */
class FortunesChange
{
    public $options = [];

    public function __construct()
    {

    }

    /**
     * @param array $recode
     * @param string $start_time
     * @param string $type
     * @return array
     */
    public function init($recode = [], $start_time = '2018-12', $type = 'month')
    {
        $type = strtolower($type);

        if ($type === 'year')
        {
            $map = ['rid' => $recode['id'], 'year' => $start_time];

            $data = (new YearFortune())->getDatas($map);
        } else
        {
            $map = ['rid' => $recode['id'], 'month' => $start_time];

            $monthData = (new MonthFortune())->getMonthFortune($map);

            $data['topics'] = json_decode($monthData, true);
        }

        return $this->getFortuneData($data, $type, $recode);
    }

    /**
     * @param array $recode
     * @param string $start_time
     * @param string $type
     * @return array
     * @throws \ApiException
     */
    public function jobInit($recode = [], $start_time = '2018-12', $type = 'month')
    {
        $type = strtolower($type);

        $recode['longitude'] = ($recode['long_deg'] + $recode['long_min'] / 60) * $recode['ew'];
        $recode['latitude'] = ($recode['lat_deg'] + $recode['lat_min'] / 60) * $recode['ns'];

        $Astrolog = Astrolog::getInstance();

        $Astrolog->setRecode1($recode)
            ->setExecPrefix(config('astrolog.prefix'))
            ->setIsAstrolabe(false)
            ->setUserSetting(config('astroset.setting1'))
            ->setGetDatas(['natal', 'transits', 'thirdprogressed']);

        $Horoscope = HoroscopeData::getInstance(['recode' => $recode]);

        $timestamp = strtotime($start_time . '-01 12:00');
        $max_change = '+1 month';
        $change = '+1 day';

        $data = [];

        for ($i = $timestamp; $i < strtotime($max_change, $timestamp); $i = strtotime($change, $i))
        {
            $date = date('Y-m-d H:i', $i);
            // 推进时间
            $advanceInfo = [
                'year' => intval(date('Y', $i)),
                'month' => intval(date('m', $i)),
                'day' => intval(date('d', $i)),
                'hour' => intval(date('H', $i)),
                'minute' => intval(date('i', $i)),
                'timezone' => 8,
                'is_summer' => 0,
                'longitude' => $recode['longitude'],// 使用本命经纬度
                'latitude' => $recode['latitude'],// 使用本命经纬度
            ];
            $Astrolog->setAdvance($advanceInfo)
            ->getAstroDatas();

            $source = [
                'sex' => $recode['type'],
                'natal_data' => $Astrolog->getDatas('natal'),
                'transits_data' => $Astrolog->getDatas('transits'),
                'thirdprogressed_data' => $Astrolog->getDatas('thirdprogressed'),
            ];

            $this->options = ['date' => $date];

            $day = date('Y-m-d', $i);
            /**
             * 获取月运、年运 运势主题
             */
            $data['topics'][$day] = $this->getTopics($source);
            /**
             * 若为年运，开始计算运势分数
             */
            if ($type === 'year')
            {
                // 获取每日运势-吉凶分数
                $luckdisasters = new LuckdisastersController();
                $luckdisasters->transitsData = $source['transits_data'];
                $luckdisasters->thirdprogressedData = $source['thirdprogressed_data'];
                $data['scores'][$i] = $luckdisasters->initForYear();
                $data['scores'][$i][0] = $this->getThirdprogressedScoreByDay($source);

                $Horoscope->option['advance']['year'] = date('Y', $i);
                $conclusion = $Horoscope->yearConclusion();
                $data['topic'] = $conclusion['topic'];
                $data['point'] = $conclusion['point'];
            }
        }
        return $data;
    }

    /**
     * 获取运势返回给客户端的数据
     * @param array $data
     * @param string $type
     * @param array $recode
     * @param string $change
     * @return array
     */
    public function getFortuneData($data = [], $type = 'month', $recode = [], $change = '+1 day')
    {
        if ($recode['type'] == 1)
        {
            $sex = 1;
        } else
        {
            $sex = 2;
        }
        // 今天的日期  年-月-日
        $today = strtotime(date('Y-m-d', time()));
        // 配置文件中存储的月运、年运运势词条
        $fortune_texts = config('fortune_text.common');
        $fortune_level1_display = config('fortune_text.level1_display');
        $has_love = $has_work = $has_money = false;

        if ($type == 'year')
        {
            $fortune_text_topic = config('fortune_text.topic');

            $fortune_topic = isset($fortune_text_topic[$data['topic']]) ? $fortune_text_topic[$data['topic']] :
                ['title' => '', 'text' => ''];

            $fortune_topic_text = isset($fortune_topic['text_' . $sex]) ? $fortune_topic['text_' . $sex] : $fortune_topic['text'];

            $result['fortune_year_stage'] = [];
            $result['fortune_year_change'] = [];
            $result['fortune_year_summarize'] = [
                'replace' => $fortune_topic['title'],
                'text' => ['        今年是你的[TOPIC]，' . $fortune_topic_text,],
            ];
        } else
        {
            $result['underway_fortune'] = [];
            $result['predicted_fortune'] = [];
            $result['completed_fortune'] = [];
        }
        if (empty($data) || empty($data['topics']) || ($type == 'year' && empty($data['scores'])))
        {
            return $result;
        }

        $temp = $list = [];
        /**
         * $day string 日期  年-月-日
         * $topic array 具体主题
         */
        foreach ($data['topics'] as $day => $topic)
        {
            foreach ($topic as $t)
            {
                /**
                 * 格式重组
                 * 将同一个运势放到一起
                 * 里面存放每一个日期和运势级别
                 */
                $temp[$t['flag']][] = ['day' => $day, 'level' => $t['level']];
            }
        }

        foreach ($temp as $k => $tmp)
        {
            $i = null;
            $j = -1;
            foreach ($tmp as $index => $t)
            {
                $level = $t['level'];
                unset($t['level']);
                /**
                 * 2018.12.01 这种格式的strtotime 无法转化  返回false
                 * 2018-12-01 可以正常转化
                 */
                $date_timestamp = strtotime($t['day'] . ' 00:00:00');
                /**
                 * 若 i 为 null 表示此运势为一段新的运势
                 */
                if ($i === null || ($type === 'month' && $date_timestamp - strtotime($change, $i) > 0)
                    || ($type === 'year' && $date_timestamp - strtotime('+1 week', $i) > 0))
                {
                    $j++;
                    $t['start_time'] = $date_timestamp;
                    $t['end_time'] = $date_timestamp;
                    unset($t['day']);
                    $list[$k][$j] = $t;
                    $list[$k][$j]['level'][] = $level;

                } /**
                 * 若 i 不为null 则表示此 可能为连续运势 需要进行比对
                 */
                elseif ($i !== null)
                {
                    if ($type === 'month')
                    {
                        if ($date_timestamp - strtotime($change, $i) == 0)
                        {
                            $list[$k][$j]['end_time'] = $date_timestamp;
                            $list[$k][$j]['level'][] = $level;
                        }
                    } else
                    {
                        if ($date_timestamp - strtotime('+1 week', $i) <= 0)
                        {
                            $list[$k][$j]['end_time'] = $date_timestamp;
                            $list[$k][$j]['level'][] = $level;
                        }
                    }

                }
                /**
                 * 记录运势的上一个时间
                 * 由于里层foreach遍历的是同一个运势
                 * 用于检测当前运势是否为连续区间
                 */
                $i = $date_timestamp;
            }
        }
        // 年运里面同一主题出现超过3次的，把持续天数最低的去掉，直到只剩三次
        if ($type === 'year')
        {
            foreach ($list as $k1 => $l1)
            {
                // 年运去除只持续一天的主题
                foreach ($l1 as $k2 => $l2)
                {
                    if ($l2['end_time'] - $l2['start_time'] < 86400 * 2)
                    {
                        unset($list[$k1][$k2]);
                    }
                }
                $list[$k1] = array_merge($list[$k1]);
                if (count($list[$k1]) == 0)
                {
                    unset($list[$k1]);
                }

            }

            foreach ($list as $k1 => $l1)
            {
                $count = count($l1);
                if ($count > 3)
                {
                    $new_tmp = [];
                    foreach ($l1 as $k2 => $l2)
                    {
                        $con_tmp = $l2['end_time'] - $l2['start_time'];

                        $new_tmp[$k2] = $con_tmp;
                    }
                    rsort($new_tmp);
                    $temp = [];
                    $ii = 0;
                    foreach ($new_tmp as $k3 => $l3)
                    {
                        if ($ii > 2) break;
                        $temp[] = $list[$k1][$k3];
                        $ii++;
                    }
                    $list[$k1] = $temp;
                }
            }
        }

        $fortune_year_stage = [];

        foreach ($list as $key => $l)
        {
            $imp = explode('-', $key);
            $fortune_text = $fortune_texts[intval($imp[0])];
            $num = intval($imp[1]);
            foreach ($l as $d)
            {
                $d['icon'] = $fortune_text['icon'];
                $d['title'] = $fortune_text[$num]['title'];
                $d['status'] = $fortune_text[$num]['status'];
                // 新增的区分男女的词条
                if (isset($fortune_text[$num . '_' . $sex]) && $fortune_text[$num . '_' . $sex] != '')
                {
                    $d['text'] = $fortune_text[$num . '_' . $sex]['text'];
                } else
                {
                    $d['text'] = $fortune_text[$num]['text'];
                }

                if ($type === 'month')
                {
                    $d['suggestion_text'] = $fortune_text[$num]['suggestion_text'];
                    $all_days = ($d['end_time'] - $d['start_time']) / 86400 + 1;
                    $d['all_days'] = $all_days;
                    /**
                     * 未来的运势
                     * level 显示第一天的级别
                     */
                    if ($today < $d['start_time'])
                    {
                        //predicted_fortune
                        $d['level'] = $d['level'][0];
                        $d['start_days'] = 0;
                        $d['end_days'] = ($d['end_time'] - $d['start_time']) / 86400 + 1;
                        $d['start_time'] = date('Y.m.d', $d['start_time']);
                        $d['end_time'] = date('Y.m.d', $d['end_time']);
                        $result['predicted_fortune'][] = $d;
                    } /**
                     * 进行中的运势
                     * level 显示当天的级别
                     */
                    elseif ($today >= $d['start_time'] && $today <= $d['end_time'])
                    {
                        //underway_fortune
                        $index = ($today - $d['start_time']) / 86400;
                        $d['level'] = $d['level'][$index];
                        $d['start_days'] = $index + 1;
                        $d['end_days'] = ($d['end_time'] - $today) / 86400;
                        $d['start_time'] = date('Y.m.d', $d['start_time']);
                        $d['end_time'] = date('Y.m.d', $d['end_time']);
                        $result['underway_fortune'][] = $d;
                    } /**
                     * 已完成的运势
                     * level 显示这段运势中最高的级别
                     */
                    elseif ($today > $d['end_time'])
                    {
                        //completed_fortune
                        $d['level'] = max($d['level']);
                        $d['start_days'] = ($d['end_time'] - $d['start_time']) / 86400 + 1;
                        $d['end_days'] = 0;
                        $d['start_time'] = date('Y.m.d', $d['start_time']);
                        $d['end_time'] = date('Y.m.d', $d['end_time']);
                        $result['completed_fortune'][] = $d;
                    }
                } else
                {
                    $year_days = ($d['end_time'] - $d['start_time']) / 86400 + 1;

                    $d['level'] = round(array_sum($d['level']) / count($d['level']));
                    $d['start_time'] = date('Y.m.d', $d['start_time']);
                    $d['end_time'] = date('Y.m.d', $d['end_time']);


                    // 暂时年运只显示2🌟及以上的
                    // 1🌟连续时间10天及以上的
                    if ($d['level'] >= 2
                        || ($d['level'] >= 1
                            && in_array($key, $fortune_level1_display)
                            && $year_days >= 10))
                    {
                        $fortune_year_stage[] = $d;
                    }
                }
            }
        }
        if ($type === 'month')
        {
            $result['predicted_fortune'] = $this->resortFortuneByTime($result['predicted_fortune']);
            $result['completed_fortune'] = $this->resortFortuneByTime($result['completed_fortune']);
            $result['underway_fortune'] = $this->resortFortuneByTime($result['underway_fortune']);
        } else
        {
            $result['fortune_year_stage'] = $this->resortFortuneByTime($fortune_year_stage);
        }

        if ($type === 'year')
        {
            $i_pre = [null, null, null, null, null];

            $scores = $scoresInfo = [];

            foreach ($data['scores'] as $in => $score)
            {
                $next_in = strtotime($change, $in);
                foreach ($score as $k => $s)
                {
                    $i_next = $data['scores'][$next_in][$k] ?? null;

                    $date_time = date('Y-m-d', $in);

                    if ($i_pre[$k] === null || $i_next === null ||
                        ($i_pre[$k] !== null && $i_next !== null
                            && (($s > $i_pre[$k] && $s > $i_next)
                                || ($s < $i_pre[$k] && $s < $i_next))))
                    {
                        // 在所有的分数基础上加20分
                        $s += 20;
                        // 溢出判断处理
                        $sc = $s > 100 ? 100 : ($s < -100 ? -100 : $s);
                        // 记录婚恋、财富、事业相关数据
                        if ($k > 0)
                        {
                            $scores[$k][] = $sc;
                            $scoresInfo[$k][] = [
                                'time' => $in,
                                'score' => $sc,
                            ];
                        }
                        // 加入到返回给客户端的数组中
                        $result['fortune_year_change'][$k][] = [
                            'time' => $date_time,
                            'score' => $sc,
                        ];
                        // 上一个点的分数
                        $i_pre[$k] = $s;
                    }
                }
            }
            // 婚恋曲线平均值
            $score1_avg = array_sum($scores[1]) / count($scores[1]);
            // 财富曲线平均值
            $score2_avg = array_sum($scores[2]) / count($scores[2]);
            // 事业曲线平均值
            $score3_avg = array_sum($scores[3]) / count($scores[3]);


            $scoresInfo[1] = resort($scoresInfo[1], 'score');
            $scoresInfo[2] = resort($scoresInfo[2], 'score');
            $scoresInfo[3] = resort($scoresInfo[3], 'score');


            $fortune_text_point = config('fortune_text.point');
            $point_temp = [];
            if (!empty($data['point']))
            {
                foreach ($data['point'] as $point)
                {
                    /**
                     * 记录是否包含三大类 婚恋、财富、事业 做曲线分析使用
                     * 婚恋 0～6
                     * 事业 7～12
                     * 财富 13～18
                     */
                    if ($has_love === false && $point >= 0 && $point <= 6)
                    {
                        $has_love = $point;
                    } elseif ($has_work === false && $point >= 7 && $point <= 12)
                    {
                        $has_work = $point;
                    } elseif ($has_money === false && $point >= 13 && $point <= 18)
                    {
                        $has_money = $point;
                    }
                    $point_temp[$point] = $fortune_text_point[$point];
                }
            } else
            {
                $result['fortune_year_outline'] = [];
            }

            /**
             * 开始曲线图分析
             * 1 婚恋
             * 2 财富
             * 3 事业
             */
            $text1 = '';
            $text1 .= $this->getAvgText(1, $score1_avg, $has_love);
            $text1 .= $this->getHighScoreText(1, $scoresInfo[1], $score1_avg);
            $text1 .= $this->getLowScoreText(1, resort($scoresInfo[1], 'score', 'ASC'), $score1_avg);

            $text2 = '';
            $text2 .= $this->getAvgText(2, $score2_avg, $has_work);
            $text2 .= $this->getHighScoreText(2, $scoresInfo[2], $score2_avg);
            $text2 .= $this->getLowScoreText(2, resort($scoresInfo[2], 'score', 'ASC'), $score2_avg);

            $text3 = '';
            $text3 .= $this->getAvgText(3, $score3_avg, $has_money);
            $text3 .= $this->getHighScoreText(3, $scoresInfo[3], $score3_avg);
            $text3 .= $this->getLowScoreText(3, resort($scoresInfo[3], 'score', 'ASC'), $score3_avg);

            if ($has_love !== false)
            {
                $point_temp[$has_love]['text'] .= $text1;
            } else
            {
                $point_temp[] = [
                    'title' => '婚恋',
                    'text' => $text1,
                    'state' => '4',
                ];
            }

            if ($has_money !== false)
            {
                $point_temp[$has_money]['text'] .= $text2;
            } else
            {
                $point_temp[] = [
                    'title' => '财富',
                    'text' => $text2,
                    'state' => '4',
                ];
            }

            if ($has_work !== false)
            {
                $point_temp[$has_work]['text'] .= $text3;
            } else
            {
                $point_temp[] = [
                    'title' => '事业',
                    'text' => $text3,
                    'state' => '4',
                ];
            }


            if (!empty($point_temp))
            {
                $result['fortune_year_outline'] = array_merge(resort($point_temp, 'state'));
            }
        }
        return $result;
    }

    /**
     * 获取平均值词条补充
     * @param int $type 1=>婚恋,2=>事业,3=>财富,
     * @param null $score 平均值
     * @param bool $has
     * @return string
     */
    public function getAvgText($type = 1, $score = null, $has = false)
    {
        $text = '';
        switch ($type)
        {
            // 婚恋
            case 1:
                if ($score > 80)
                {
                    if ($has)
                    {
                        $text .= '从婚恋曲线图上看来，';
                    }
                    $text .= '你的感情正处于极其活跃的时期，这会让你有很多的情感机会或将感情发展作为今年的重心。';
                } elseif ($score >= 40 && $score < 80)
                {
                    if ($has)
                    {
                        $text .= '从婚恋曲线图上看来，';
                    }
                    $text .= '你今年的感情非常活跃，会花费很多心力在婚恋方面，将比往年有更多的情感契机。';
                } elseif ($score >= 0 && $score < 40)
                {
                    $text = '从婚恋曲线图来看，你的整体感情运势较好，把握机会可能得到意想不到的收获。';
                } elseif ($score >= -40 && $score < 0)
                {
                    if ($has)
                    {
                        $text .= '由婚恋曲线图来看，';
                    }
                    $text .= '你今年的感情运不算太好，有可能造成一些困扰，但很容易克服。';
                } else
                {
                    if ($has)
                    {
                        $text .= '由婚恋曲线图来看，';
                    }
                    $text .= '你的整体感情运相对比较低迷，如果已有伴侣，需要关注与伴侣间的关系，可能会有较多争吵不和，而没有伴侣的话，这一年能获得好桃花的机会并不高，当然也可能仅仅是遭受一些阻碍，具体还请与阶段运势综合参考。';
                }
                break;
            // 事业
            case 3:
                if ($score > 80)
                {
                    if ($has)
                    {
                        $text .= '从事业曲线图上看来，';
                    }
                    $text .= '你的事业正处于一个非常好的时期，比较顺心，有被升职加薪的可能，或是得到上级的重视，如果正在求职中，也能够找到满意的工作。';
                } elseif ($score >= 40 && $score < 80)
                {
                    if ($has)
                    {
                        $text .= '从事业曲线图上看来，';
                    }
                    $text .= '你今年的事业发展将有更广阔的空间，你也会把许多精力放在事业的打拼上，只要尽心尽力，就能取得收获。';
                } elseif ($score >= 0 && $score < 40)
                {
                    if ($has)
                    {
                        $text .= '从事业曲线图来看，';
                    }
                    $text .= '你的整体事业运较好，可能会有意想不到的机会，让你离实现自己的事业目标更近一步。';
                } elseif ($score >= -40 && $score < 0)
                {
                    if ($has)
                    {
                        $text .= '由事业曲线图来看，';
                    }
                    $text .= '你今年的事业运不算太好，有可能面临一些挫折，但调整好心态，就能战胜困难，突破自我。';
                } else
                {
                    if ($has)
                    {
                        $text .= '由事业曲线图看来，';
                    }
                    $text .= '你的整体事业运相对比较低迷，工作不是很顺心，也不容易遇到更好的机会。如果有想换工作的想法，还是要仔细考量，不要裸辞。工作中难免遇到一些小挫折，但不要轻易选择退缩，而是要提高自身能力。';
                }
                break;
            // 财富
            default:
                if ($score > 80)
                {
                    if ($has)
                    {
                        $text .= '从财富曲线图上看来，';
                    }
                    $text .= '从财富曲线图上看来，你正处于财运非常旺的阶段，可能会有赚外快的机会，或是升职加薪，如果你自己做生意，也会收益颇丰、财源滚滚。';
                } elseif ($score >= 40 && $score < 80)
                {
                    if ($has)
                    {
                        $text .= '从财富曲线图看来，';
                    }
                    $text .= '你今年的财运很棒，财务方面能够得到一个大的提升，可能是来自于工作，或是一些偏财收入。';
                } elseif ($score >= 0 && $score < 40)
                {
                    if ($has)
                    {
                        $text .= '从财富曲线图来看，';
                    }
                    $text .= '你今年的整体财运较好，不会为金钱问题烦恼，除了正财以外，勤快一点，还会有赚外快的机会。';
                } elseif ($score >= -40 && $score < 0)
                {
                    if ($has)
                    {
                        $text .= '由财富曲线图来看，';
                    }
                    $text .= '你今年的财运有点吃紧，不是说没有赚钱的机会，只是可能花销开支较大，有点入不敷出。';
                } else
                {
                    if ($has)
                    {
                        $text .= '由财富曲线图看来，';
                    }
                    $text .= '你今年的整体财运不是太好，可能会陷入财务困境，或是破财。˙虽然很渴望财运能够有所提升，但又没有太有利于赚钱的机会。这个年份不要对偏财抱希望，还是提高个人能力，踏实努力赚钱。';
                }
                break;
        }
        return $text;
    }

    /**
     * 获取高点词条补充
     * @param int $type
     * @param array $score
     * @param null $avg
     * @return string
     */
    public function getHighScoreText($type = 1, $score = [], $avg = null)
    {
        $text = '';
        switch ($type)
        {
            case 1:
                $text0 = '前后是你感情运最佳的时段，除了被动的等待契机，也可以在这段时间去主动示好、沟通、发出邀请，往往能获得让你满意的回应，让感情得到进展。';
                $text1 = '感情运相对较好，若能把握机会仍然会有很好的契机，或许是感情的转折点。建议主动向喜欢的人示好、发出邀请。';
                break;
            case 3:
                $text0 = '前后是你事业运最棒的时段，如果你有什么好的想法，比如升职加薪，或想跳槽，可以准备起来，往往能获得让你满意的结果。';
                $text1 = '事业运较好，会有好的机会出现，或是有工作上的好事，也可能是事业上的转折点，如果有创业、跳槽的想法，可以行动起来';
                break;
            default:
                $text0 = '前后是你财运最好的时段，你可能会被加薪、或是从其他方面获利，如果有投资理财的打算，也比较适合。若是有人欠你钱未还，可以在这个时段试着讨回。';
                $text1 = '财运相对较好，挣钱比较轻松，也会有其他额外收入。';
                break;
        }
        $n = 0;
        $arr = [];
        for ($i = 0; $i < 5; $i++)
        {
            if(!isset($score[$i])) continue;
            $date_m = date('n', $score[$i]['time']);
            $date_d = date('d', $score[$i]['time']);
            if ($date_d < 10) $date_x = '上旬';
            elseif ($date_d < 20) $date_x = '中旬';
            else $date_x = '下旬';

            $date_mx = $date_m . '月' . $date_x;
            if (!in_array($date_mx, $arr))
            {
                if ($i == 0)
                {
                    $arr[] = $date_mx;
                    $text .= $date_mx;
                    if ($avg >= 0)
                    {
                        $text .= $text0;
                    } else
                    {
                        $text .= $text1;
                    }
                    $n++;
                } elseif ($i == 1)
                {
                    $arr[] = $date_mx;
                    $text .= '其它不错的时间段还有' . $date_mx;
                    $n++;
                } elseif ($i > 1 && $score[1]['score'] - $score[$i]['score'] < 20)
                {
                    $arr[] = $date_mx;
                    if ($n == 1) $text .= '其它不错的时间段还有' . $date_mx;
                    else $text .= '、' . $date_mx;
                    $n++;
                }
            }
        }
        $text .= '。';

        return $text;
    }

    /**
     * 获取低点词条补充
     * @param int $type
     * @param array $score
     * @param null $avg
     * @return string
     */
    public function getLowScoreText($type = 1, $score = [], $avg = null)
    {
        $text = '';
        switch ($type)
        {
            case 1:
                $text0 = '是你今年的情感低谷，有可能会遭遇一点挫折，建议在低谷到来之前就注意与伴侣协调好关系。其实运势高低变化再正常不过，这只是一个相对较差的阶段，也许小吵一架就过去了，也许什么都不会发生。';
                $text1 = '可能是今年最差的感情阶段，如有问题在那之前就会露出端倪，建议提前注意，可将问题扼杀在摇篮之中。';
                break;
            case 3:
                $text0 = '前后是你事业上的低迷期，有可能遇到一点挫折和挑战，建议在低迷到来之前就注意处理好工作上的事情，以免哪里处理不当留下隐患。其实运势高低都正常不过，不要有心理负担，也许遇到一点小小的不顺心，也许什么都不会发生。';
                $text1 = '可能是今年最差的事业阶段，或许会感受到一些压力和阻碍，或是工作中出现一些其他问题，让你有所困扰。建议不要浮躁，认真做好自己的工作，不要掺和太多工作以外的事情。';
                break;
            default:
                $text0 = '前后，你财务容易陷入一个比较窘困的状态，财务压力有点大，可能是花销开支增多或财物丢失。建议要理性消费，不要为了满足一时的物质需求而选择透支。';
                $text1 = '可能是今年财务最吃紧的时段，金钱压力较大，但财运好坏都是阶段性的，当下不好，不代表以后不会好转。';
                break;
        }
        $n = 0;
        $arr = [];
        for ($i = 0; $i < 5; $i++)
        {
            if(!isset($score[$i])) continue;
            $date_m = date('n', $score[$i]['time']);
            $date_d = date('d', $score[$i]['time']);
            if ($date_d < 10) $date_x = '上旬';
            elseif ($date_d < 20) $date_x = '中旬';
            else $date_x = '下旬';

            $date_mx = $date_m . '月' . $date_x;
            if (!in_array($date_mx, $arr))
            {
                if ($i == 0)
                {
                    $arr[] = $date_mx;
                    $text .= $date_mx;
                    if ($avg >= 0)
                    {
                        $text .= $text0;
                    } else
                    {
                        $text .= $text1;
                    }
                    $n++;
                } elseif ($i == 1)
                {
                    $arr[] = $date_mx;
                    $text .= '其它需要注意的时间段还有' . $date_mx;
                    $n++;
                } elseif ($i > 1 && $score[$i]['score'] - $score[1]['score'] < 20)
                {
                    $arr[] = $date_mx;
                    if ($n == 1) $text .= '其它需要注意的时间段还有' . $date_mx;
                    else $text .= '、' . $date_mx;
                    $n++;
                }
            }
        }
        $text .= '。';

        return $text;
    }

    /**
     * 对运势结果按运势开始时间&&结束时间进行排序
     * @param array $data
     * @param string $sort
     * @return array
     */
    private function resortFortuneByTime($data = [], $sort = 'ASC')
    {
        if (!empty($data))
        {
            foreach ($data as $k1 => $d1)
            {
                foreach ($data as $k2 => $d2)
                {
                    if ($k1 < $k2)
                    {
                        if (strtoupper($sort) === 'ASC')
                        {
                            $k1_start_time = strtotime(str_replace('.', '-', $data[$k1]['start_time']));
                            $k2_start_time = strtotime(str_replace('.', '-', $data[$k2]['start_time']));
                            if ($k1_start_time > $k2_start_time)
                            {
                                $temp = $data[$k1];
                                $data[$k1] = $data[$k2];
                                $data[$k2] = $temp;
                            } // 开始时间一致，则比较结束时间
                            elseif ($k1_start_time == $k2_start_time)
                            {
                                $k1_end_time = strtotime(str_replace('.', '-', $data[$k1]['end_time']));
                                $k2_end_time = strtotime(str_replace('.', '-', $data[$k2]['end_time']));
                                if ($k1_end_time > $k2_end_time)
                                {
                                    $temp = $data[$k1];
                                    $data[$k1] = $data[$k2];
                                    $data[$k2] = $temp;
                                }
                            }
                        }
                    }
                }
            }
        }
        return $data;
    }

    /**
     * 获取三限每天的分数
     * @param array $source
     * @return float|int|mixed
     */
    public function getThirdprogressedScoreByDay($source = [])
    {
        $source_moon = $this->getPlanetScore(1, $source['thirdprogressed_data']);
        $source_sun = $this->getPlanetScore(0, $source['thirdprogressed_data']);
        $source_venu = $this->getPlanetScore(3, $source['thirdprogressed_data']);
        $source_merc = $this->getPlanetScore(2, $source['thirdprogressed_data']);

        $fiveScore = $this->getFiveItemScore($source);

        $good = $source_moon['inc'] + $source_sun['inc'] / 2 + $source_venu['inc'] / 3 + $source_merc['inc'] / 3;
        $bad = $source_moon['dec'] + $source_sun['dec'] / 2 + $source_venu['dec'] / 3 + $source_merc['dec'] / 3;

        // 计算合轴得分 上升-下降
        if (!empty($source['planets'][ASC]['phase']))
        {
            foreach ($source['planets'][ASC]['phase'] as $phase)
            {
                if (in_array($phase['id'], [0, 2, 3, 4, 6, 7, 8, 9]) && in_array($phase['phase_e'], [0, 180]))
                {
                    $change1 = $this->getChangeByAxis($phase['id']);

                    if ($change1 > 0) $good += $change1;
                    else $bad += $change1;
                }
            }
        }
        // 计算合轴得分 天顶-天底
        if (!empty($source['planets'][MC]['phase']))
        {
            foreach ($source['planets'][MC]['phase'] as $phase)
            {
                if (in_array($phase['id'], [0, 2, 3, 4, 6, 7, 8, 9]) && in_array($phase['phase_e'], [0, 180]))
                {
                    $change2 = $this->getChangeByAxis($phase['id']);

                    if ($change2 > 0) $good += $change2;
                    else $bad += $change2;
                }
            }
        }
        $score = ($good - $bad) + ($fiveScore[2] * 2 - $fiveScore[3] - $fiveScore[4]);

        $score = round($score);

        return $score;
    }

    /**
     * 获取行星分数
     * @param int $pid
     * @param array $source
     * @return array
     */
    public function getPlanetScore($pid = 1, $source = [])
    {
        $inc = $dec = 0;// 加分减分初始化为0

        $planet = $source['planets'][$pid];// 当前行星数据
        $p_inhouse = $planet['in_house_id'];// 当前行星落宫id
        $structure = $source['structure'];// 当前星盘所有结构数据

        if (!empty($planet['phase']))
        {
            // 若同时有火土海冥刑冲或同时与火土海冥之二成相
            $is_phase_4689 = false;
            $phase_4689_num = 0;
            if (checkPhase([$pid], [4, 6, 8, 9], [90, 180], $source))
            {
                $is_phase_4689 = true;
            }
            if (isset($planet['phase'][$pid . '-4'])) $phase_4689_num++;
            if (isset($planet['phase'][$pid . '-6'])) $phase_4689_num++;
            if (isset($planet['phase'][$pid . '-8'])) $phase_4689_num++;
            if (isset($planet['phase'][$pid . '-9'])) $phase_4689_num++;
            if ($phase_4689_num >= 2)
            {
                $is_phase_4689 = true;
            }

            foreach ($planet['phase'] as $phase)
            {
                $temp1 = $temp2 = 0;
                // 成相星体落宫id
                $phase_in_house = $source['planets'][$phase['id']]['in_house_id'];

                // 三限容许系数
                $phase_orb_modulus = getThirdprogressedModulus($phase['phase_orb']);

                // 火土海冥
                if (in_array($phase['id'], [4, 6, 8, 9]))
                {
                    // 刑冲 -10
                    if (in_array($phase['phase_e'], [90, 180]))
                    {
                        $temp2 += 10;
                        // 相位一端在12宫，额外-6
                        if ($p_inhouse == 12 || $phase_in_house == 12)
                        {
                            $temp2 += 6;
                        }
                        // 相位一端在8宫，额外-4
                        if ($p_inhouse == 8 || $phase_in_house == 8)
                        {
                            $temp2 += 4;
                        }
                        // 相位一端在6宫，额外-2
                        if ($p_inhouse == 6 || $phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                        // 构成T三角，额外-8 只计算一次
                        if (is_in_t_square($structure['t_square'], 0))
                        {
                            $temp2 += 8;
                        }
                    } // 合-5
                    elseif ($phase['phase_e'] == 0)
                    {
                        $temp2 += 5;
                        //  相位一端在12宫，额外-4
                        if ($p_inhouse == 12 || $phase_in_house == 12)
                        {
                            $temp2 += 4;
                        }
                        //  相位一端在8宫，额外-3
                        if ($p_inhouse == 8 || $phase_in_house == 8)
                        {
                            $temp2 += 3;
                        }
                        //  相位一端在6宫，额外-2
                        if ($p_inhouse == 6 || $phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                        // 月亮在火土海冥之间且同时合相，额外-5
                        //  即火土海冥之二，与月亮合，且月亮位于两者中间 只计算一次

                    } // 拱六分-3
                    elseif (in_array($phase['phase_e'], [60, 120]))
                    {
                        $temp2 += 3;
                        // 相位一端在12宫，额外-4
                        if ($p_inhouse == 12 || $phase_in_house == 12)
                        {
                            $temp2 += 4;
                        }
                        // 相位一端在8宫，额外-3
                        if ($p_inhouse == 8 || $phase_in_house == 8)
                        {
                            $temp2 += 3;
                        }
                        // 相位一端在6宫，额外-2
                        if ($p_inhouse == 6 || $phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                        //  构成闭合三角且月亮仅与火土天海冥成相，额外-6 只计算一次

                    }
                } //天王
                elseif ($phase['id'] == 7)
                {
                    // 刑冲 -5
                    if (in_array($phase['phase_e'], [90, 180]))
                    {
                        $temp2 += 5;
                        // 相位一端在12宫，额外-4
                        if ($p_inhouse == 12 || $phase_in_house == 12)
                        {
                            $temp2 += 4;
                        }
                        // 相位一端在8宫，额外-3
                        if ($p_inhouse == 8 || $phase_in_house == 8)
                        {
                            $temp2 += 3;
                        }
                        // 相位一端在6宫，额外-2
                        if ($p_inhouse == 6 || $phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                        // 若同时有火土海冥刑冲或同时与火土海冥之二成相，额外-4
                        // 若星盘上有日||金||水参与的T三角（火||土||冥||海必参与一个），则额外-5

                    } // 合-1
                    elseif ($phase['phase_e'] == 0)
                    {
                        $temp2 += 1;
                        // 若同时有火土海冥刑冲或同时与火土海冥之二成相，额外-3
                        if ($is_phase_4689)
                        {
                            $temp2 += 3;
                        }
                        // 若同时与金木之一成相，额外+5
                        if (isset($planet['phase'][$pid . '-3']) || isset($planet['phase'][$pid . '-5']))
                        {
                            $temp1 += 5;
                        }
                    } // 拱六分-0
                    elseif (in_array($phase['phase_e'], [60, 120]))
                    {
                        $temp2 += 0;
                        // 若同时有火土海冥刑冲或同时与火土海冥之二成相，额外-2
                        if ($is_phase_4689)
                        {
                            $temp2 += 2;
                        }
                        // 若同时与金木之一成相或天王与金木之一成合拱六分，额外+4
                        //  即 月亮与金木之一成相 或 天王与金木之一成合拱六分
                        if ((isset($planet['phase'][$pid . '-3']) || isset($planet['phase'][$pid . '-5']))
                            ||
                            (
                                (isset($planet['phase']['7-3'])
                                    && in_array($planet['phase']['7-3']['phase_e'], [0, 60, 120]))
                                || (isset($planet['phase']['7-5'])
                                    && in_array($planet['phase']['7-5']['phase_e'], [0, 60, 120]))
                            )
                        )
                        {
                            $temp1 += 4;
                        }
                    }
                } // 金木
                elseif (in_array($phase['id'], [3, 5]))
                {
                    // 合+10
                    if ($phase['phase_e'] == 0)
                    {
                        $temp1 += 10;
                    } // 拱六分+7
                    elseif (in_array($phase['phase_e'], [60, 120]))
                    {
                        $temp1 += 7;
                    } // 冲+7
                    elseif ($phase['phase_e'] == 180)
                    {
                        $temp1 += 7;
                    } // 刑+3-3
                    elseif ($phase['phase_e'] == 90)
                    {
                        $temp1 += 3;
                        $temp2 += 3;
                    }
                    // 月亮在5/11宫+3
                    if (in_array($p_inhouse, [5, 11]))
                    {
                        $temp1 += 3;
                    }
                    // 月亮在1/4/7/10+2
                    if (in_array($p_inhouse, [1, 4, 7, 10]))
                    {
                        $temp1 += 2;
                    }
                } // 日水
                elseif (in_array($phase['id'], [0, 2]))
                {
                    // 合+-0
                    if ($phase['phase_e'] == 0)
                    {
                        $temp1 += 0;
                        $temp2 += 0;
                    } // 拱六分+2
                    elseif (in_array($phase['phase_e'], [60, 120]))
                    {
                        $temp1 += 2;
                    } // 冲-1
                    elseif ($phase['phase_e'] == 180)
                    {
                        $temp2 += 1;
                        // 相位一端在6/8/12宫分别额外-2/3/4
                        if ($phase_in_house == 12)
                        {
                            $temp2 += 4;
                        } elseif ($phase_in_house == 8)
                        {
                            $temp2 += 3;
                        } elseif ($phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                    } // 刑-3
                    elseif ($phase['phase_e'] == 90)
                    {
                        $temp2 += 3;
                        // 相位一端在6/8/12宫分别额外-2/3/4
                        if ($phase_in_house == 12)
                        {
                            $temp2 += 4;
                        } elseif ($phase_in_house == 8)
                        {
                            $temp2 += 3;
                        } elseif ($phase_in_house == 6)
                        {
                            $temp2 += 2;
                        }
                    }
                }

                $inc += $temp1 * $phase_orb_modulus;
                $dec += $temp2 * $phase_orb_modulus;
            }
        } // 若月亮空相，计算月亮宫位吉凶
        else
        {
            if ($p_inhouse == 1)
            {
                $inc += 6;
            } elseif ($p_inhouse == 2)
            {
                $inc += 1;
            } elseif ($p_inhouse == 3)
            {
                $inc += 3;
            } elseif ($p_inhouse == 4)
            {
                $inc += 5;
            } elseif ($p_inhouse == 5)
            {
                $inc += 10;
            } elseif ($p_inhouse == 6)
            {
                $dec += -3;
            } elseif ($p_inhouse == 7)
            {
                $inc += 6;
            } elseif ($p_inhouse == 8)
            {
                $dec += -5;
            } elseif ($p_inhouse == 9)
            {
                $inc += 7;
            } elseif ($p_inhouse == 10)
            {
                $inc += 6;
            } elseif ($p_inhouse == 11)
            {
                $inc += 7;
            } elseif ($p_inhouse == 12)
            {
                $dec += -7;
            }
        }

        return ['inc' => $inc, 'dec' => $dec];
    }

    /**
     * 合轴加分
     * @param int $pid
     * @return int
     */
    private function getChangeByAxis($pid = 0)
    {
        $change = 0;
        switch ($pid)
        {
            case 0:
                $change += 3;
                break;
            case 2:
                $change += 2;
                break;
            case 3:
                $change += 10;
                break;
            case 4:
                $change += -10;
                break;
            case 6:
                $change += -10;
                break;
            case 7:
                $change += -3;
                break;
            case 8:
                $change += -10;
                break;
            case 9:
                $change += -9;
                break;
            default:
                $change += 0;
                break;
        }
        return $change;
    }

    /**
     * 行运活跃分
     * 五项指数
     * 出行 社交/桃花 开心 愤怒/意外 郁闷
     * @param array $source
     * @return array
     */
    public function getFiveItemScore($source = [])
    {
        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘

        // 出行 社交/桃花 开心 愤怒/意外 郁闷
        $score1 = $score2 = $score3 = $score4 = $score5 = 0;
        $score1_num = $score2_num = $score3_num = $score4_num = $score5_num = 0;
        // 遍历日月水金火
        foreach ([0, 1, 2, 3, 4] as $i)
        {
            if (!empty($tr_planet1[$i]['phase']))
            {
                foreach ($tr_planet1[$i]['phase'] as $phase)
                {
                    if ($i == 0)
                    {
                        if ($phase['phase_e'] != 90)
                        {
                            // 日水非刑
                            if ($phase['id'] == 2)
                            {
                                $score1 += 4;
                                $score1_num++;
                            } // 日金非刑
                            elseif ($phase['id'] == 3)
                            {
                                $score2 += 5;
                                $score2_num++;
                                //日金合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 5;
                                    $score3_num++;
                                } // 日金冲
                                else
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                }
                            } // 日火
                            elseif ($phase['id'] == 4)
                            {
                                if ($phase['phase_e'] == 0)
                                {
                                    $score4 += 4;
                                    $score4_num++;
                                } // 拱六分
                                elseif (in_array($phase['phase_e'], [60, 120]))
                                {
                                    $score4 += 3;
                                    $score4_num++;
                                }
                            }
                            // 日木非刑
                            if ($phase['id'] == 5)
                            {
                                $score1 += 5;
                                $score1_num++;
                                //日木合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 5;
                                    $score3_num++;
                                } // 日木冲
                                else
                                {
                                    $score3 += 4;
                                    $score3_num++;
                                }
                            }
                            // 日土/日海/日冥合
                            if (in_array($phase['id'], [6, 8, 9]))
                            {
                                if ($phase['phase_e'] == 0)
                                {
                                    $score5 += 4;
                                    $score5_num++;
                                } elseif (in_array($phase['phase_e'], [60, 120]))
                                {
                                    // 日土/日海/日冥拱六分
                                    $score5 += 3;
                                    $score5_num++;
                                }
                            }
                            if ($phase['id'] == 1 && $phase['phase_e'] == 180)
                            {
                                $score5 += 1;
                                $score5_num++;
                            }
                        } else
                        {

                            if ($phase['id'] == 1)
                            {
                                $score5 += 3;
                                $score5_num++;
                            } // 日水刑
                            elseif ($phase['id'] == 2)
                            {
                                $score1 += 1;
                                $score1_num++;
                                $score5 += 3;
                                $score5_num++;
                            } // 日金刑
                            elseif ($phase['id'] == 3)
                            {
                                $score2 += 1;
                                $score2_num++;
                                $score5 += 1;
                                $score5_num++;
                            } // 日木刑
                            elseif ($phase['id'] == 5)
                            {
                                $score1 += 1;
                                $score1_num++;
                                $score5 += 1;
                                $score5_num++;
                            }
                        }
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            // 日火刑冲
                            if ($phase['id'] == 4)
                            {
                                $score4 += 5;
                                $score4_num++;
                            } elseif ($phase['id'] == 7)
                            {
                                $score5 += 3;
                                $score5_num++;
                            } // 日土/日海/日冥刑冲
                            elseif (in_array($phase['id'], [6, 8, 9]))
                            {
                                $score5 += 5;
                                $score5_num++;
                            }
                        }
                    } elseif ($i == 1)
                    {
                        if ($phase['phase_e'] != 90)
                        {
                            // 月水合拱六分
                            if ($phase['id'] == 2)
                            {
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score1 += 0.5;
                                    $score1_num++;
                                }
                            } // 月金合拱六分
                            elseif ($phase['id'] == 3)
                            {
                                $score3 += 0.5;
                                $score3_num++;
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score2 += 0.5;
                                    $score2_num++;
                                }
                            } // 月木合拱六分
                            elseif ($phase['id'] == 5)
                            {
                                $score3 += 0.5;
                                $score3_num++;
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score1 += 0.5;
                                    $score1_num++;
                                }
                            }
                        } // 月与任意星体刑
                        else
                        {
                            $score5 += 0.5;
                            $score5_num++;
                        }
                        // 月火
                        if ($phase['id'] == 4)
                        {
                            $score4 += 0.5;
                            $score4_num++;
                        }
                    } elseif ($i == 2)
                    {
                        if ($phase['phase_e'] != 90)
                        {
                            // 水日非刑
                            if ($phase['id'] == 0)
                            {
                                $score1 += 4;
                                $score1_num++;
                            } // 水月非刑
                            elseif ($phase['id'] == 1)
                            {
                                $score1 += 4;
                                $score1_num++;
                            } // 水金非刑
                            elseif ($phase['id'] == 3)
                            {
                                $score1 += 1;
                                $score1_num++;
                                $score2 += 4;
                                $score2_num++;
                                // 水金合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                } // 水木/水金冲
                                else
                                {
                                    $score3 += 1;
                                    $score3_num++;
                                }
                            } elseif ($phase['id'] == 4)
                            {
                                // 水火合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score4 += 3;
                                    $score4_num++;
                                }
                            } // 水木非刑
                            elseif ($phase['id'] == 5)
                            {
                                $score1 += 5;
                                $score1_num++;
                                //水木合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                } // 水木/水金冲
                                else
                                {
                                    $score3 += 1;
                                    $score3_num++;
                                }
                            }
                            if (in_array($phase['phase_e'], [0, 180]))
                            {
                                // 水星合上升下降
                                if ($phase['id'] == ASC)
                                {
                                    $score1 += 4;
                                    $score1_num++;
                                } // 水星合天顶天底
                                elseif ($phase['id'] == MC)
                                {
                                    $score1 += 3;
                                    $score1_num++;
                                }
                            }
                        } else
                        {
                            // 水日刑
                            if ($phase['id'] == 0)
                            {
                                $score1 += 3;
                                $score1_num++;
                                $score5 += 3;
                                $score5_num++;
                            } // 水月刑
                            elseif ($phase['id'] == 1)
                            {
                                $score1 += 3;
                                $score1_num++;
                            } elseif ($phase['id'] == 3)
                            {
                                $score5 += 1;
                                $score5_num++;
                            } // 水木刑
                            elseif ($phase['id'] == 5)
                            {
                                $score1 += 1;
                                $score1_num++;
                                $score5 += 1;
                                $score5_num++;
                            }
                        }

                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            // 水火
                            if ($phase['id'] == 4)
                            {
                                $score4 += 4;
                                $score4_num++;
                            } elseif ($phase['id'] == 7)
                            {
                                $score5 += 3;
                                $score5_num++;
                            } // 水土/水海/水冥刑冲
                            elseif (in_array($phase['id'], [6, 8, 9]))
                            {
                                $score5 += 4;
                                $score5_num++;
                            }
                        }

                        // 水土/水海/水冥合
                        if (in_array($phase['id'], [6, 8, 9]) && $phase['phase_e'] == 0)
                        {
                            $score5 += 3;
                            $score5_num++;
                        }

                    } elseif ($i == 3)
                    {
                        if ($phase['phase_e'] != 90)
                        {
                            // 金日非刑
                            if ($phase['id'] == 0)
                            {
                                $score2 += 5;
                                $score2_num++;
                                // 金日合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 5;
                                    $score3_num++;
                                } // 金日冲
                                else
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                }
                            } // 金月非刑
                            elseif ($phase['id'] == 1)
                            {
                                $score2 += 5;
                                $score2_num++;
                                // 金月合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 5;
                                    $score3_num++;
                                } // 金月冲
                                else
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                }
                            } // 金水非刑
                            elseif ($phase['id'] == 2)
                            {
                                $score2 += 4;
                                $score2_num++;
                                // 金水合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                } // 金木/金水冲
                                else
                                {
                                    $score3 += 1;
                                    $score3_num++;
                                }
                            } // 金金非刑
                            elseif ($phase['id'] == 3)
                            {
                                $score2 += 5;
                                $score2_num++;
                                // 金金合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 5;
                                    $score3_num++;
                                }
                            } elseif ($phase['id'] == 4)
                            {
                                // 金火合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score2 += 4;
                                    $score2_num++;
                                    $score4 += 3;
                                    $score4_num++;
                                }
                            } // 金木非刑
                            elseif ($phase['id'] == 5)
                            {
                                $score1 += 1;
                                $score1_num++;
                                $score2 += 2;
                                $score2_num++;
                                // 金木合拱六分
                                if (in_array($phase['phase_e'], [0, 60, 120]))
                                {
                                    $score3 += 3;
                                    $score3_num++;
                                } // 金木/金水冲
                                else
                                {
                                    $score3 += 1;
                                    $score3_num++;
                                }
                            } elseif ($phase['id'] == ASC)
                            {
                                // 金合上升/下降
                                if (in_array($phase['phase_e'], [0, 180]))
                                {
                                    $score2 += 5;
                                    $score2_num++;
                                    $score3 += 5;
                                    $score3_num++;
                                }
                            } elseif ($phase['id'] == MC)
                            {
                                // 金合天顶天底
                                if (in_array($phase['phase_e'], [0, 180]))
                                {
                                    $score2 += 4;
                                    $score2_num++;
                                }
                            }
                            // 金土/金海/金冥合
                            if (in_array($phase['id'], [6, 8, 9]) && $phase['phase_e'] == 0)
                            {
                                $score5 += 3;
                                $score5_num++;
                            }
                        } else
                        {
                            if ($phase['id'] == 0)
                            {
                                $score2 += 1;
                                $score2_num++;
                                $score5 += 1;
                                $score5_num++;
                            } elseif ($phase['id'] == 1)
                            {
                                $score2 += 1;
                                $score2_num++;
                            } elseif ($phase['id'] == 2)
                            {
                                $score2 += 1;
                                $score2_num++;
                                $score5 += 1;
                                $score5_num++;
                            } elseif ($phase['id'] == 3)
                            {
                                $score2 += 1;
                                $score2_num++;
                            } elseif ($phase['id'] == 5)
                            {
                                $score2 += 1;
                                $score2_num++;
                                $score5 += 1;
                                $score5_num++;
                            }
                        }
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            // 金火
                            if ($phase['id'] == 4)
                            {
                                $score4 += 4;
                                $score4_num++;
                            } elseif ($phase['id'] == 7)
                            {
                                $score5 += 3;
                                $score5_num++;
                            } // 金土/金海/金冥刑冲
                            elseif (in_array($phase['id'], [6, 8, 9]))
                            {
                                $score5 += 4;
                                $score5_num++;
                            }
                        }
                    } elseif ($i == 4)
                    {
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            // 火日刑冲
                            if ($phase['id'] == 0)
                            {
                                $score4 += 5;
                                $score4_num++;
                            } // 火月刑冲
                            elseif ($phase['id'] == 1)
                            {
                                $score4 += 5;
                                $score4_num++;
                            } // 火水
                            elseif ($phase['id'] == 2)
                            {
                                $score4 += 4;
                                $score4_num++;
                            } // 火金
                            elseif ($phase['id'] == 3)
                            {
                                $score4 += 4;
                                $score4_num++;
                            } // 与木土天海冥
                            elseif (in_array($phase['id'], [5, 6, 7, 8, 9]))
                            {
                                $score4 += 1;
                                $score4_num++;
                            }
                            // 刑上升下降
                            if ($phase['phase_e'] == 90 && $phase['id'] == ASC)
                            {
                                $score4 += 1;
                                $score4_num++;
                            }
                            // 火刑冲命宫内星
                            if ($tr_planet2[$phase['id']]['in_house_id'] == 1)
                            {
                                $score4 += 1;
                                $score4_num++;
                            }
                        } // 拱六分
                        elseif (in_array($phase['phase_e'], [60, 120]))
                        {
                            if ($phase['id'] == 0)
                            {
                                $score4 += 3;
                                $score4_num++;
                            } elseif ($phase['id'] == 1)
                            {
                                $score4 += 3;
                                $score4_num++;
                            }
                        }
                        if (in_array($phase['phase_e'], [0, 180]))
                        {
                            // 火合升降
                            if ($phase['id'] == ASC)
                            {
                                $score4 += 5;
                                $score4_num++;
                            } // 天顶天底
                            elseif ($phase['id'] == MC)
                            {
                                $score4 += 3;
                                $score4_num++;
                            }
                        }
                        if ($phase['phase_e'] == 0)
                        {
                            // 火日
                            if ($phase['id'] == 0)
                            {
                                $score4 += 4;
                                $score4_num++;
                            } // 火月
                            elseif ($phase['id'] == 1)
                            {
                                $score4 += 4;
                                $score4_num++;
                            }

                        }
                        // 合拱六分
                        if (in_array($phase['phase_e'], [0, 60, 120]))
                        {
                            // 火水
                            if ($phase['id'] == 2)
                            {
                                $score4 += 3;
                                $score4_num++;
                            }
                        }
                    }
                    if (in_array($i, [0, 1, 2, 3]))
                    {
                        if (in_array($phase['phase_e'], [0, 60, 120]))
                        {
                            // 日月金水与3/9宫宫内星合拱六分
                            if (in_array($tr_planet2[$phase['id']]['in_house_id'], [3, 9]))
                            {
                                $score1 += 3;
                                $score1_num++;
                            } elseif (in_array($tr_planet2[$phase['id']]['in_house_id'], [5, 7, 11]))
                            {
                                $score2 += 2;
                                $score2_num++;
                            }

                        }
                    }
                }
            }
            if (in_array($i, [0, 2, 3]))
            {
                if ($tr_planet1[$i]['in_house_id'] == 12)
                {
                    $score5 += 2;
                    $score5_num++;
                } elseif ($tr_planet1[$i]['in_house_id'] == 8)
                {
                    $score5 += 1;
                    $score5_num++;
                }
            }
            if (in_array($i, [0, 1, 2, 3]))
            {
                // 日月金水落3/9宫
                if (in_array($tr_planet1[$i]['in_house_id'], [3, 9]))
                {
                    $score1 += 1;
                    $score1_num++;
                } elseif (in_array($tr_planet1[$i]['in_house_id'], [5, 7, 11]))
                {
                    $score2 += 1;
                    $score2_num++;
                }

            } // 火星
            else
            {
                // 火落1/7
                if (in_array($tr_planet2[$i]['in_house_id'], [1, 7]))
                {
                    $score4 += 1;
                    $score4_num++;
                }
            }
        }

//        $level1 = $level2 = $level3 = $level4 = $level5 = 0;
//
//
//        $tp1_phase4689_num = 0;
//        $tp1_phase4689_090180_num = 0;
//        $tp1_phase6789_num = 0;
//        $tp1_phase6789_90180_num = 0;
//
//        if (!empty($tp_planet[1]['phase']))
//        {
//            foreach ($tp_planet[1]['phase'] as $phase)
//            {
//                if (in_array($phase['id'], [4, 6, 8, 9]))
//                {
//                    $tp1_phase4689_num++;
//                    if (in_array($phase['phase_e'], [0, 90, 180]))
//                    {
//                        $tp1_phase4689_090180_num++;
//                    }
//                }
//                if (in_array($phase['id'], [6, 7, 8, 9]))
//                {
//                    $tp1_phase6789_num++;
//                    if (in_array($phase['phase_e'], [90, 180]))
//                    {
//                        $tp1_phase6789_90180_num++;
//                    }
//                }
//            }
//        }
//
//        if ($score1 >= 9 || $score1_num >= 4)
//        {
//            $level1 = 2;
//            if (in_array($tp_planet[1]['in_house_id'], [3, 9])
//                || (checkPhase([1], [2, 5], [0, 60, 120, 180], $tp_planet)))
//            {
//                $level1 = 3;
//            }
//        } elseif ($score1 >= 5 || $score1_num >= 3)
//        {
//            $level1 = 1;
//        }
//
//        if ($score2 >= 9 || $score2_num >= 4)
//        {
//            $level2 = 2;
//            if (in_array($tp_planet[1]['in_house_id'], [5, 7, 11])
//                || (checkPhase([1], [3, 5], [0, 60, 120, 180], $tp_planet)))
//            {
//                $level2 = 3;
//            }
//        } elseif ($score2 >= 5 || $score2_num >= 3)
//        {
//            $level2 = 1;
//        }
//
//        if ($score3 >= 9 || $score3_num >= 4)
//        {
//            $level3 = 2;
//            if ($tp1_phase4689_090180_num == 0 || $tp1_phase4689_num < 2)
//            {
//                $level3 = 3;
//            }
//        } elseif ($score3 >= 5 || $score3_num >= 3)
//        {
//            $level3 = 1;
//        }
//
//        if ($score4 >= 9 || $score4_num >= 4)
//        {
//            $level4 = 2;
//            if ($tp1_phase6789_num >= 2 || (checkPhase([1], [4], [], $tp_planet)))
//            {
//                $level4 = 3;
//            }
//        } elseif ($score4 >= 5 || $score4_num >= 3)
//        {
//            $level4 = 1;
//        }
//
//        if ($score5 >= 9 || $score5_num >= 4)
//        {
//            $level5 = 2;
//            if ($tp1_phase6789_90180_num >= 1 || $tp1_phase6789_num >= 2)
//            {
//                $level5 = 3;
//            }
//        } elseif ($score5 >= 5 || $score5_num >= 3)
//        {
//            $level5 = 1;
//        }

//        $result = [$level1, $level2, $level3, $level4, $level5];

        $score = [$score1, $score2, $score3, $score4, $score5];

        return $score;
    }

    /**
     * 获取所有的主题
     * @param array $source
     * @return array
     */
    public function getTopics($source = [])
    {
        $loveTopic = $this->getLoveTopic($source);
        $careerTopic = $this->getCareerTopic($source);
        $healthTopic = $this->getHealthTopic($source);
        $treasureTopic = $this->getTreasureTopic($source);
        $familyTopic = $this->getFamilyTopic($source);
        $contactTopic = $this->getContactTopic($source);
        $moodTopic = $this->getMoodTopic($source);
        $travelTopic = $this->getTravelTopic($source);

        $result = array_merge($loveTopic, $careerTopic, $healthTopic, $treasureTopic, $familyTopic, $contactTopic, $moodTopic, $travelTopic);

        return $result;
    }

    /**
     * 婚恋主题
     * @param array $source
     * @return array
     */
    public function getLoveTopic($source = [])
    {
        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        $natal = $source['natal_data']['planets'];// 本命盘

        $result = [];

        //春光灿烂桃花开
        $score1_1 = $score1_2 = $level = 0;// 正分 负分 初始化
        // tp日金合+10
        if (isset($tp_planet[0]['phase']['0-3']) && $tp_planet[0]['phase']['0-3']['phase_e'] == 0)
        {
            $score1_1 += 10;
        }
        // tp金火成相
        if (isset($tp_planet[3]['phase']['3-4']))
        {
            // 合+15
            if ($tp_planet[3]['phase']['3-4']['phase_e'] == 0)
            {
                $score1_1 += 15;
            } // 冲拱六分+10
            elseif (in_array($tp_planet[3]['phase']['3-4']['phase_e'], [60, 120, 180]))
            {
                $score1_1 += 10;
            } // 刑+4
            elseif ($tp_planet[3]['phase']['3-4']['phase_e'] == 90)
            {
                $score1_1 += 4;
            }
        }
        // tp金木成相
        if (isset($tp_planet[3]['phase']['3-5']))
        {
            // 合+10
            if ($tp_planet[3]['phase']['3-5']['phase_e'] == 0)
            {
                $score1_1 += 10;
            } // 冲拱六分+7
            elseif (in_array($tp_planet[3]['phase']['3-5']['phase_e'], [60, 120, 180]))
            {
                $score1_1 += 7;
            } // 刑+6
            elseif ($tp_planet[3]['phase']['3-5']['phase_e'] == 90)
            {
                $score1_1 += 6;
            }
        }
        // tp金星在5/7宫或合四轴+5
        if (in_array($tp_planet[3]['in_house_id'], [5, 7])
            || (isset($tp_planet[3]['phase']['3-' . ASC]) && in_array($tp_planet[3]['phase']['3-' . ASC], [0, 180]))
            || (isset($tp_planet[3]['phase']['3-' . MC]) && in_array($tp_planet[3]['phase']['3-' . MC], [0, 180]))
        )
        {
            $score1_1 += 5;
        }
        // tp木星在5/7宫+5
        if (in_array($tp_planet[5]['in_house_id'], [5, 7]))
        {
            $score1_1 += 5;
        }
        // tp月亮过5/7宫+5
        if (in_array($tp_planet[1]['in_house_id'], [5, 7]))
        {
            $score1_1 += 5;
        }
        // tp月亮与金星成非刑相+7
        if (isset($tp_planet[1]['phase']['1-3']) && $tp_planet[1]['phase']['1-3']['phase_e'] != 90)
        {
            $score1_1 += 7;
        }
        // tr木星在5/7宫+8
        if (in_array($tr_planet1[5]['in_house_id'], [5, 7]))
        {
            $score1_1 += 8;
        }
        // tr木星与金星（或5、7宫内的日月火木）成相
        if (isset($tr_planet1[5]['phase']['5-3']))
        {
            // 冲合+10
            if (in_array($tr_planet1[5]['phase']['5-3']['phase_e'], [0, 180]))
            {
                $score1_1 += 10;
            } // 拱六分+6
            elseif (in_array($tr_planet1[5]['phase']['5-3']['phase_e'], [60, 120]))
            {
                $score1_1 += 6;
            } // 刑+7
            elseif ($tr_planet1[5]['phase']['5-3']['phase_e'] == 90)
            {
                $score1_1 += 7;
            }
        }
        // tr木星与5/7 宫内太阳
        if (in_array($tr_planet2[0]['in_house_id'], [5, 7]) && isset($tr_planet1[5]['phase']['5-0']))
        {
            // 冲合+10
            if (in_array($tr_planet1[5]['phase']['5-0']['phase_e'], [0, 180]))
            {
                $score1_1 += 10;
            } // 拱六分+6
            elseif (in_array($tr_planet1[5]['phase']['5-0']['phase_e'], [60, 120]))
            {
                $score1_1 += 6;
            } // 刑+7
            elseif ($tr_planet1[5]['phase']['5-0']['phase_e'] == 90)
            {
                $score1_1 += 7;
            }
        }
        // tr木星与5/7 宫内月亮
        if (in_array($tr_planet2[1]['in_house_id'], [5, 7]) && isset($tr_planet1[5]['phase']['5-1']))
        {
            // 冲合+10
            if (in_array($tr_planet1[5]['phase']['5-1']['phase_e'], [0, 180]))
            {
                $score1_1 += 10;
            } // 拱六分+6
            elseif (in_array($tr_planet1[5]['phase']['5-1']['phase_e'], [60, 120]))
            {
                $score1_1 += 6;
            } // 刑+7
            elseif ($tr_planet1[5]['phase']['5-1']['phase_e'] == 90)
            {
                $score1_1 += 7;
            }
        }
        // tr木星与5/7 宫内火星
        if (in_array($tr_planet2[4]['in_house_id'], [5, 7]) && isset($tr_planet1[5]['phase']['5-4']))
        {
            // 冲合+10
            if (in_array($tr_planet1[5]['phase']['5-4']['phase_e'], [0, 180]))
            {
                $score1_1 += 10;
            } // 拱六分+6
            elseif (in_array($tr_planet1[5]['phase']['5-4']['phase_e'], [60, 120]))
            {
                $score1_1 += 6;
            } // 刑+7
            elseif ($tr_planet1[5]['phase']['5-4']['phase_e'] == 90)
            {
                $score1_1 += 7;
            }
        }
        // tr木星与5/7 宫内木星
        if (in_array($tr_planet2[5]['in_house_id'], [5, 7]) && isset($tr_planet1[5]['phase']['5-5']))
        {
            // 冲合+10
            if (in_array($tr_planet1[5]['phase']['5-5']['phase_e'], [0, 180]))
            {
                $score1_1 += 10;
            } // 拱六分+6
            elseif (in_array($tr_planet1[5]['phase']['5-5']['phase_e'], [60, 120]))
            {
                $score1_1 += 6;
            } // 刑+7
            elseif ($tr_planet1[5]['phase']['5-5']['phase_e'] == 90)
            {
                $score1_1 += 7;
            }
        }
        // tr天海冥之一与金星成相
        // 天
        if (isset($tr_planet1[7]['phase']['7-3']))
        {
            // 冲合+5
            if (in_array($tr_planet1[7]['phase']['7-3']['phase_e'], [0, 180]))
            {
                $score1_1 += 5;
            } // 拱六分+3
            elseif (in_array($tr_planet1[7]['phase']['7-3']['phase_e'], [60, 120]))
            {
                $score1_1 += 3;
            } // 刑+3
            elseif ($tr_planet1[7]['phase']['7-3']['phase_e'] == 90)
            {
                $score1_1 += 3;
            }
        }
        // 海
        if (isset($tr_planet1[8]['phase']['8-3']))
        {
            // 冲合+5
            if (in_array($tr_planet1[8]['phase']['8-3']['phase_e'], [0, 180]))
            {
                $score1_1 += 5;
            } // 拱六分+3
            elseif (in_array($tr_planet1[8]['phase']['8-3']['phase_e'], [60, 120]))
            {
                $score1_1 += 3;
            } // 刑+3
            elseif ($tr_planet1[8]['phase']['8-3']['phase_e'] == 90)
            {
                $score1_1 += 3;
            }
        }
        // 冥
        if (isset($tr_planet1[9]['phase']['9-3']))
        {
            // 冲合+5
            if (in_array($tr_planet1[9]['phase']['9-3']['phase_e'], [0, 180]))
            {
                $score1_1 += 5;
            } // 拱六分+3
            elseif (in_array($tr_planet1[9]['phase']['9-3']['phase_e'], [60, 120]))
            {
                $score1_1 += 3;
            } // 刑+3
            elseif ($tr_planet1[9]['phase']['9-3']['phase_e'] == 90)
            {
                $score1_1 += 3;
            }
        }
        // tr金星过5/7宫+2
        if (in_array($tr_planet1[3]['in_house_id'], [5, 7]))
        {
            $score1_1 += 2;
        }
        // tr金星与日、金、火、上升冲合+2
        // 日
        if (isset($tr_planet1[3]['phase']['3-0']) && in_array($tr_planet1[3]['phase']['3-0']['phase_e'], [0, 180]))
        {
            $score1_1 += 2;
        }
        // 金
        if (isset($tr_planet1[3]['phase']['3-3']) && in_array($tr_planet1[3]['phase']['3-3']['phase_e'], [0, 180]))
        {
            $score1_1 += 2;
        }
        // 火
        if (isset($tr_planet1[3]['phase']['3-4']) && in_array($tr_planet1[3]['phase']['3-4']['phase_e'], [0, 180]))
        {
            $score1_1 += 2;
        }
        // 上升
        if (isset($tr_planet1[3]['phase']['3-' . ASC]) && in_array($tr_planet1[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
        {
            $score1_1 += 2;
        }
        // tp土星刑冲金星-50
        if (isset($tp_planet[6]['phase']['6-3']))
        {
            // 刑冲 -50
            if (in_array($tp_planet[6]['phase']['6-3']['phase_e'], [90, 180]))
            {
                $score1_2 += 50;
            }// 合 -30
            elseif ($tp_planet[6]['phase']['6-3']['phase_e'] == 0)
            {
                $score1_2 += 30;
            }// 拱六分 -20 （土星在5/7宫或合轴时生效）
            elseif (in_array($tp_planet[6]['phase']['6-3']['phase_e'], [60, 120])
                && (
                    in_array($tp_planet[6]['in_house_id'], [5, 7])
                    || (isset($tp_planet[6]['phase']['6-' . ASC])
                        && in_array($tp_planet[6]['phase']['6-' . ASC]['phase_e'], [0, 180]))
                    || (isset($tp_planet[6]['phase']['6-' . MC])
                        && in_array($tp_planet[6]['phase']['6-' . MC]['phase_e'], [0, 180]))
                )
            )
            {
                $score1_2 += 20;
            }
        }
        // tp土星刑冲太阳-20
        if (isset($tp_planet[6]['phase']['6-0']) && in_array($tp_planet[6]['phase']['6-0']['phase_e'], [90, 180]))
        {
            $score1_2 += 20;
        }
        // tr土星刑冲金星-35
        if (isset($tr_planet1[6]['phase']['6-3']))
        {
            // 刑冲金星-35
            if (in_array($tr_planet1[6]['phase']['6-3']['phase_e'], [90, 180]))
            {
                $score1_2 += 35;
            }// tr土星合金星-15
            elseif ($tr_planet1[6]['phase']['6-3']['phase_e'] == 0)
            {
                $score1_2 += 15;
            }// tr土星拱六分金星-5
            elseif (in_array($tr_planet1[6]['phase']['6-3']['phase_e'], [60, 120]))
            {
                $score1_2 += 5;
            }
        }
        // tr土星刑冲太阳-15
        if (isset($tr_planet1[6]['phase']['6-0']) && in_array($tr_planet1[6]['phase']['6-0']['phase_e'], [90, 180]))
        {
            $score1_2 += 15;
        }
        // tr土星合上升-10
        if (isset($tr_planet1[6]['phase']['6-' . ASC]) && $tr_planet1[6]['phase']['6-' . ASC]['phase_e'] == 0)
        {
            $score1_2 += 10;
        }

        // 计算星级
        $level = $this->modLevel5(floor(($score1_1 - $score1_2) / 10));

        //  注：正负分单独计算，若负分大于等于30，且正分超过10，则将主题改为“一场苦恋，爱而不得”，正分每10分为1个星级
        if ($score1_2 >= 30 && $score1_1 >= 10)
        {
            if ($level > 0)
            {
                $temp = [
                    'flag' => '0-2',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        } else
        {
            if ($level > 0)
            {
                $temp = [
                    'flag' => '0-1',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        // “桃花开”主题高于10分
        if ($score1_1 - $score1_2 >= 10)
        {
            //情与爱的迷局
            $score2 = $level = 0;// 正分 负分 初始化
            // tp金星与海王成相
            if (isset($tp_planet[3]['phase']['3-8']))
            {
                // 刑冲 +10
                if (in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180]))
                {
                    $score2 += 10;
                }// 合 +8
                elseif (in_array($tp_planet[3]['phase']['3-8']['phase_e'], [0]))
                {
                    $score2 += 8;
                }// 拱六分 +5
                elseif (in_array($tp_planet[3]['phase']['3-8']['phase_e'], [60, 120]))
                {
                    $score2 += 5;
                }
            }
            // tp火星与海王成相
            if (isset($tp_planet[4]['phase']['4-8']))
            {
                // 刑冲 +10
                if (in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180]))
                {
                    $score2 += 10;
                }// 合 +8
                elseif (in_array($tp_planet[4]['phase']['4-8']['phase_e'], [0]))
                {
                    $score2 += 8;
                }// 拱六分 +5
                elseif (in_array($tp_planet[4]['phase']['4-8']['phase_e'], [60, 120]))
                {
                    $score2 += 5;
                }
            }
            // 海王合下降+7
            if (isset($tp_planet[8]['phase']['8-' . ASC]) && $tp_planet[8]['phase']['8-' . ASC]['phase_e'] == 180)
            {
            } else
            {
                // 海王在7宫且不合下降+3
                if ($tp_planet[8]['in_house_id'] == 7)
                {
                    $score2 += 3;
                    // 合刑冲日月+7
                    if ((isset($tp_planet[8]['phase']['8-0'])
                            && in_array($tp_planet[8]['phase']['8-0']['phase_e'], [0, 90, 180]))
                        ||
                        (isset($tp_planet[8]['phase']['8-1'])
                            && in_array($tp_planet[8]['phase']['8-1']['phase_e'], [0, 90, 180]))
                    )
                    {
                        $score2 += 7;
                    }
                }
            }
            // 海王在5宫+3
            if ($tp_planet[8]['in_house_id'] == 5)
            {
                $score2 += 3;
                // 合刑冲日月+7
                if ((isset($tp_planet[8]['phase']['8-0'])
                        && in_array($tp_planet[8]['phase']['8-0']['phase_e'], [0, 90, 180]))
                    ||
                    (isset($tp_planet[8]['phase']['8-1'])
                        && in_array($tp_planet[8]['phase']['8-1']['phase_e'], [0, 90, 180]))
                )
                {
                    $score2 += 7;
                }
            }
            // 是否满足以上任意条件
            $is_true = $score2 > 0;
            // 月海成相（满足以上任意一个条件时）+7
            if (isset($tp_planet[1]['phase']['1-8']) && $is_true)
            {
                $score2 += 7;
            }
            // 月亮过5/7宫（满足以上任意一个条件时）+5
            if (in_array($tp_planet[1]['in_house_id'], [5, 7]) && $is_true)
            {
                $score2 += 5;
            }
            // 月亮与金星成相（满足以上任意一个条件时）+5
            if (isset($tp_planet[1]['phase']['1-3']) && $is_true)
            {
                $score2 += 5;
            }
            $is_true = false;
            // tr海王刑冲合金星+10
            if (isset($tr_planet1[8]['phase']['8-3']) && in_array($tr_planet1[8]['phase']['8-3']['phase_e'], [0, 90, 180]))
            {
                $score2 += 10;
                $is_true = true;
            }
            // 海王刑冲合火星+8
            if (isset($tr_planet1[8]['phase']['8-4']) && in_array($tr_planet1[8]['phase']['8-4']['phase_e'], [0, 90, 180]))
            {
                $score2 += 8;
                $is_true = true;
            }
            // 海王刑冲合月亮+3
            if (isset($tr_planet1[8]['phase']['8-1']) && in_array($tr_planet1[8]['phase']['8-1']['phase_e'], [0, 90, 180]))
            {
                $score2 += 3;
                // 满足以上任一条件时+7
                if ($is_true === true)
                {
                    $score2 += 7;
                }
            }
            // 海王刑冲合太阳+3
            if (isset($tr_planet1[8]['phase']['8-0']) && in_array($tr_planet1[8]['phase']['8-0']['phase_e'], [0, 90, 180]))
            {
                $score2 += 3;
                // 满足以上任一条件时+7
                if ($is_true === true)
                {
                    $score2 += 7;
                }
            }
            if (isset($tr_planet1[8]['phase']['8-' . ASC]))
            {
                // 海王合上升（+3）
                if ($tr_planet1[8]['phase']['8-' . ASC]['phase_e'] == 0)
                {
                    $score2 += 3;
                }// 海王合下降（+5）
                elseif ($tr_planet1[8]['phase']['8-' . ASC]['phase_e'] == 180)
                {
                    $score2 += 5;
                }
            }
            // 海王在5/7宫（+3）
            if (in_array($tr_planet1[8]['in_house_id'], [5, 7]))
            {
                $score2 += 3;
            }

            // 计算星级
            $level = $this->modLevel5(floor($score2 / 10));

            if ($level > 0)
            {
                $temp = [
                    'flag' => '0-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        //问世间情为何物
        $score3 = $level = 0;// 正分 负分 初始化
        //tp金星与冥王刑冲+8，合+5，拱六分+4
        if (isset($tp_planet[3]['phase']['3-9']))
        {
            $tp_phase_3_9 = $tp_planet[3]['phase']['3-9']['phase_e'];
            // 刑冲+8
            if (in_array($tp_phase_3_9, [90, 180]))
            {
                $score3 += 8;
            }// 合+5
            elseif (in_array($tp_phase_3_9, [0]))
            {
                $score3 += 5;
            }// 拱六分+4
            elseif (in_array($tp_phase_3_9, [60, 120]))
            {
                $score3 += 4;
            }
            // 本命有金冥刑冲合或为金天蝎+5
            if ((isset($natal[3]['phase']['3-9']) && in_array($natal[3]['phase']['3-9']['phase_e'], [0, 90, 180])) || $natal[3]['in_sign_id'] == 8)
            {
                $score3 += 5;
            }
            // tp金星在5/7/1宫+5
            if (in_array($tp_planet[3]['in_house_id'], [1, 5, 7]))
            {
                $score3 += 5;
            }
            // tp计算金星受克强度
            //      参与T三角或大十字+10
            if (!empty($tp_planet['structure']))
            {
                $venu_status = false;// 金星是否参与T三角或大十字
                if (!empty($tp_planet['structure']['t_square']))
                {
                    foreach ($tp_planet['structure']['t_square'] as $t_square)
                    {
                        // 参与T三角
                        if (!$venu_status && in_array(3, $t_square))
                        {
                            $venu_status = true;
                        }
                    }
                }
                if (!$venu_status && !empty($tp_planet['structure']['cross']))
                {
                    foreach ($tp_planet['structure']['cross'] as $cross)
                    {
                        // 参与大十字
                        if (!$venu_status && in_array(3, $cross))
                        {
                            $venu_status = true;
                        }
                    }
                }
                if ($venu_status === true)
                {
                    $score3 += 10;
                }
            }
            if (!empty($tp_planet[3]['phase']))
            {
                $tp_3_phase_46789_num = 0;// 与火土天海冥成相数量
                foreach ($tp_planet[3]['phase'] as $phase)
                {
                    if (in_array($phase['id'], [4, 6, 7, 8, 9]))
                    {
                        $tp_3_phase_46789_num++;// 与火土天海冥成相
                        // 每有一次火土天海冥的刑冲+5
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            $score3 += 5;
                        }
                        if (in_array($phase['id'], [6, 7, 8, 9]))
                        {
                            // 每有一次土天海冥的合相+4
                            if ($phase['phase_e'] == 0)
                            {
                                $score3 += 4;
                            }// 每有一次土天海冥的拱六分+3
                            elseif (in_array($phase['phase_e'], [60, 120]))
                            {
                                $score3 += 3;
                            }
                        }
                    }
                }
                // 与火土天海冥三个以上成相+3
                if ($tp_3_phase_46789_num >= 3)
                {
                    $score3 += 3;
                }
            }
            // tp月亮与金星成相+5
            if (isset($tp_planet[1]['phase']['1-3']))
            {
                $score3 += 5;
            }
            // tp月亮过5/7宫+5
            if (in_array($tp_planet[1]['in_house_id'], [5, 7]))
            {
                $score3 += 5;
            }
            // tr冥王与金星拱六分+3
            if (isset($tr_planet1[9]['phase']['9-3']) && in_array($tr_planet1[9]['phase']['9-3']['phase_e'], [60, 120]))
            {
                $score3 += 3;
            }
        }
        //tr冥王合刑冲本命金星+4
        if (isset($tr_planet1[9]['phase']['9-3'])
            && in_array($tr_planet1[9]['phase']['9-3']['phase_e'], [0, 90, 180]))
        {
            $score3 += 4;
            //  tr金星与冥王成相+4
            if (isset($tr_planet1[3]['phase']['3-9']))
            {
                $score3 += 4;
            }
            //  tr日水火与冥王成相+3
            if (isset($tr_planet1[0]['phase']['0-9'])
                || isset($tr_planet1[2]['phase']['2-9'])
                || isset($tr_planet1[4]['phase']['4-9']))
            {
                $score3 += 3;
            }
        }

        // 计算星级
        $level = $this->modLevel5(floor($score3 / 10));

        if ($level > 0)
        {
            $temp = [
                'flag' => '0-4',
                'level' => $level,
            ];
            $result[] = $temp;
        }


        //孤单寂寞冷
        $score4 = $level = 0;
        //  tp金星天王成相
        if (isset($tp_planet[3]['phase']['3-7']))
        {
            // 刑冲+10
            if (in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180]))
            {
                $score4 += 10;
            }// 拱六分+5
            elseif (in_array($tp_planet[3]['phase']['3-7']['phase_e'], [60, 120]))
            {
                $score4 += 5;
            }//合+7
            elseif (in_array($tp_planet[3]['phase']['3-7']['phase_e'], [0]))
            {
                $score4 += 7;
            }
        }
        //  tp火星与天王成相
        if (isset($tp_planet[4]['phase']['4-7']))
        {
            // 刑冲+7
            if (in_array($tp_planet[4]['phase']['4-7']['phase_e'], [90, 180]))
            {
                $score4 += 7;
            }// 拱六分+3
            elseif (in_array($tp_planet[4]['phase']['4-7']['phase_e'], [60, 120]))
            {
                $score4 += 3;
            }//合+5
            elseif (in_array($tp_planet[4]['phase']['4-7']['phase_e'], [0]))
            {
                $score4 += 5;
            }
        }
        if (isset($tp_planet[7]['phase']['7-' . ASC]))
        {
            //  tp天王合下降+10
            if (in_array($tp_planet[7]['phase']['7-' . ASC]['phase_e'], [180]))
            {
                $score4 += 10;
            }//tp天王合上升+5
            elseif (in_array($tp_planet[7]['phase']['7-' . ASC]['phase_e'], [0]))
            {
                $score4 += 5;
            }
        }
        //  tp天王合天顶、上升或天底+5
        if (isset($tp_planet[7]['phase']['7-' . MC]) && in_array($tp_planet[7]['phase']['7-' . MC]['phase_e'], [0, 180]))
        {
            $score4 += 5;
        }
        //  tp日天刑冲合+5（当金星受到土天海冥刑冲合时）
        if (isset($tp_planet[0]['phase']['0-7']) && in_array($tp_planet[0]['phase']['0-7']['phase_e'], [0, 90, 180]))
        {
            if (checkPhase([3], [6, 7, 8, 9], [0, 90, 180], $tp_planet))
            {
                $score4 += 5;
            }
        }
        //  tp月天刑冲合+5
        if (isset($tp_planet[1]['phase']['1-7']) && in_array($tp_planet[1]['phase']['1-7']['phase_e'], [0, 90, 180]))
        {
            $score4 += 5;
        }
        //  tp月亮与土冥同时成相+5（或土冥相互成相，月亮与其一成相）
        //      土冥之一位于5/7宫或合下降点+5
        if ((isset($tp_planet[1]['phase']['1-6']) && isset($tp_planet[1]['phase']['1-9']))
            ||
            (
                isset($tp_planet[6]['phase']['6-9'])
                && (isset($tp_planet[1]['phase']['1-6']) || isset($tp_planet[1]['phase']['1-9']))
            )
        )
        {
            $score4 += 5;
            if (
                in_array($tp_planet[6]['in_house_id'], [5, 7])
                || in_array($tp_planet[9]['in_house_id'], [5, 7])
                || (isset($tp_planet[6]['phase']['6-' . ASC]) && $tp_planet[6]['phase']['6-' . ASC]['phase_e'] == 180)
                || (isset($tp_planet[9]['phase']['9-' . ASC]) && $tp_planet[9]['phase']['9-' . ASC]['phase_e'] == 180)
            )
            {
                $score4 += 5;
            }
        }
        //  tr天王刑冲金星+10
        if (isset($tr_planet1[7]['phase']['7-3']))
        {
            if (in_array($tr_planet1[7]['phase']['7-3']['phase_e'], [90, 180]))
            {
                $score4 += 10;
            } // tr天王合金星+8
            elseif (in_array($tr_planet1[7]['phase']['7-3']['phase_e'], [0]))
            {
                $score4 += 8;
            }

        }
        //  tr天王刑冲合月亮+5
        //      此时天王在1/7宫+5
        if (isset($tr_planet1[7]['phase']['7-1']) && in_array($tr_planet1[7]['phase']['7-1']['phase_e'], [0, 90, 180]))
        {
            $score4 += 5;
            if (in_array($tr_planet1[7]['in_house_id'], [1, 7]))
            {
                $score4 += 5;
            }
        }

        // 计算星级
        $level = $this->modLevel5(floor($score4 / 10));

        if ($level > 0)
        {
            $temp = [
                'flag' => '0-5',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        if ($source['sex'] != 1)
        {
            //看着合适嫁了吧
            $score5 = $level = 0;
            $cond1 = $cond2 = false;
            //木星
            // tp日木成相或金木成相或木星合轴+7
            if (isset($tp_planet[0]['phase']['0-5'])
                || isset($tp_planet[3]['phase']['3-5'])
                || (isset($tp_planet[5]['phase']['5-' . ASC])
                    && in_array($tp_planet[5]['phase']['5-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[5]['phase']['5-' . MC])
                    && in_array($tp_planet[5]['phase']['5-' . MC]['phase_e'], [0, 180]))
            )
            {
                $score5 += 7;
                $cond1 = true;
            }
            // tr木星与太阳成相，或tr木星与金星成相+5
            if (isset($tr_planet1[5]['phase']['5-0']) || isset($tr_planet1[5]['phase']['5-3']))
            {
                $score5 += 5;
                $cond1 = true;
            }
            //土星
            //  tp日土成相或金土成相或土星合轴+5（非刑）
            //      此时金星不可与火天海刑冲 20190117
            if (
                !checkPhase([3], [4, 7, 8], [90, 180], $tp_planet)
                &&
                (
                    (isset($tp_planet[0]['phase']['0-6']) && $tp_planet[0]['phase']['0-6']['phase_e'] != 90)
                    || (isset($tp_planet[3]['phase']['3-6']) && $tp_planet[3]['phase']['3-6']['phase_e'] != 90)
                    || (isset($tp_planet[6]['phase']['6-' . ASC])
                        && in_array($tp_planet[6]['phase']['6-' . ASC]['phase_e'], [0, 180]))
                    || (isset($tp_planet[6]['phase']['6-' . MC])
                        && in_array($tp_planet[6]['phase']['6-' . MC]['phase_e'], [0, 180]))
                )
            )
            {
                $score5 += 5;
                $cond2 = true;
            }
            //  tr土星与太阳成相，或土星合轴
            //       tr土星与太阳合拱六分，或土星合轴 20190117
            if ((isset($tr_planet1[6]['phase']['6-0']) && in_array($tr_planet1[6]['phase']['6-0']['phase_e'], [0, 60, 120]))
                || (isset($tr_planet1[6]['phase']['6-' . ASC])
                    && in_array($tr_planet1[6]['phase']['6-' . ASC]['phase_e'], [0, 180]))
                || (isset($tr_planet1[6]['phase']['6-' . MC])
                    && in_array($tr_planet1[6]['phase']['6-' . MC]['phase_e'], [0, 180])))
            {
                $score5 += 5;
                $cond2 = true;
            }
            //两个条件都满足，本项分数与“桃花”分数相加计算星级
            if ($cond1 && $cond2)
            {
                // 计算星级
                $level = $this->modLevel5(floor($score5 / 10));

                if ($level > 0)
                {
                    $temp = [
                        'flag' => '0-6',
                        'level' => $level,
                    ];
                    $result[] = $temp;
                }
            }
        }

        //开在阴影里的花
        $score6 = $level = 0;
        //tp月亮过5/7与金星成相
        if (in_array($tp_planet[1]['in_house_id'], [5, 7]))
        {
            if (isset($tp_planet[1]['phase']['1-3']))
            {
                // 金星与天海同时刑冲+10
                if (isset($tp_planet[3]['phase']['3-7'])
                    && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180])
                    && isset($tp_planet[3]['phase']['3-8'])
                    && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180])
                )
                {
                    $score6 += 10;
                }
                // 金星与天海同时合拱六分且月亮与天海成相+10
                if (isset($tp_planet[3]['phase']['3-7'])
                    && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [0, 60, 120])
                    && isset($tp_planet[3]['phase']['3-8'])
                    && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [0, 60, 120])
                    && (isset($tp_planet[1]['phase']['1-7']) || isset($tp_planet[1]['phase']['1-8']))
                )
                {
                    $score6 += 10;
                }
            }
            //tp月亮过5/7与火星成相
            if (isset($tp_planet[1]['phase']['1-4']))
            {
                // 火星与天海刑冲+10
                if (isset($tp_planet[4]['phase']['4-7'])
                    && in_array($tp_planet[4]['phase']['4-7']['phase_e'], [90, 180])
                    && isset($tp_planet[4]['phase']['4-8'])
                    && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180])
                )
                {
                    $score6 += 10;
                }
                // 火星与天海合拱六分且月亮与天海成相+10
                if (isset($tp_planet[4]['phase']['4-7'])
                    && in_array($tp_planet[4]['phase']['4-7']['phase_e'], [0, 60, 120])
                    && isset($tp_planet[4]['phase']['4-8'])
                    && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [0, 60, 120])
                    && (isset($tp_planet[1]['phase']['1-7']) || isset($tp_planet[1]['phase']['1-8']))
                )
                {
                    $score6 += 10;
                }
            }
        }
        //tp金火在5/7宫合相且与天海之一刑冲
        if (isset($tp_planet[3]['phase']['3-4']) && $tp_planet[3]['phase']['3-4']['phase_e'] == 0
            && in_array($tp_planet[3]['in_house_id'], [5, 7]) && in_array($tp_planet[4]['in_house_id'], [5, 7])
            && (
                (isset($tp_planet[3]['phase']['3-7']) && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180]))
                || (isset($tp_planet[3]['phase']['3-8']) && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180]))
            )
            && (
                (isset($tp_planet[4]['phase']['4-7']) && in_array($tp_planet[4]['phase']['4-7']['phase_e'], [90, 180]))
                || (isset($tp_planet[4]['phase']['4-8']) && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180]))
            )
        )
        {
            if (isset($tp_planet[3]['phase']['3-7']) && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180])
                && isset($tp_planet[4]['phase']['4-7']) && in_array($tp_planet[4]['phase']['4-7']['phase_e'], [90, 180]))
            {
                // 金火与天海之中的另一个成相+10
                if (isset($tp_planet[3]['phase']['3-8']) && isset($tp_planet[4]['phase']['4-8']))
                {
                    $score6 += 10;
                }
                // 太阳与天海之中的另一个成相+10
                if (isset($tp_planet[0]['phase']['0-8']) && isset($tp_planet[0]['phase']['0-8']))
                {
                    $score6 += 10;
                }
            } elseif (isset($tp_planet[3]['phase']['3-8']) && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180])
                && isset($tp_planet[4]['phase']['4-8']) && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180]))
            {
                // 金火与天海之中的另一个成相+10
                if (isset($tp_planet[3]['phase']['3-7']) && isset($tp_planet[4]['phase']['4-7']))
                {
                    $score6 += 10;
                }
                // 太阳与天海之中的另一个成相+10
                if (isset($tp_planet[0]['phase']['0-7']) && isset($tp_planet[0]['phase']['0-7']))
                {
                    $score6 += 10;
                }
            }
            // 月亮与金火成相+10
            if (isset($tp_planet[1]['phase']['1-3']) && isset($tp_planet[1]['phase']['1-4']))
            {
                $score6 += 10;
            }
        }//tp金火合在12宫，且与天海冥之一刑冲+10
        elseif (isset($tp_planet[3]['phase']['3-4']) && $tp_planet[3]['phase']['3-4']['phase_e'] == 0
            && in_array($tp_planet[3]['in_house_id'], [12]) && in_array($tp_planet[4]['in_house_id'], [12])
            && (
                (isset($tp_planet[3]['phase']['3-7']) && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180]))
                || (isset($tp_planet[3]['phase']['3-8']) && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180]))
                || (isset($tp_planet[3]['phase']['3-9']) && in_array($tp_planet[3]['phase']['3-9']['phase_e'], [90, 180]))
            )
            && (
                (isset($tp_planet[4]['phase']['4-7']) && in_array($tp_planet[4]['phase']['4-7']['phase_e'], [90, 180]))
                || (isset($tp_planet[4]['phase']['4-8']) && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180]))
                || (isset($tp_planet[4]['phase']['4-9']) && in_array($tp_planet[4]['phase']['4-9']['phase_e'], [90, 180]))
            )
        )
        {
            $score6 += 10;
            // 月亮与金火成相+10
            if (isset($tp_planet[1]['phase']['1-3']) && isset($tp_planet[1]['phase']['1-4']))
            {
                $score6 += 10;
            }
        }
        // tp海王合升降点且与金星成相+5
        if (isset($tp_planet[8]['phase']['8-' . ASC])
            && in_array($tp_planet[8]['phase']['8-' . ASC]['phase_e'], [0, 180])
            && isset($tp_planet[8]['phase']['8-3'])
        )
        {
            $score6 += 5;
            // 日海刑+5
            if (isset($tp_planet[0]['phase']['0-8']) && $tp_planet[0]['phase']['0-8']['phase_e'] == 90)
            {
                $score6 += 5;
            }
            // 金天成相+3
            if (isset($tp_planet[3]['phase']['3-7']))
            {
                $score6 += 3;
            }
            // 金冥成相+3
            if (isset($tp_planet[3]['phase']['3-9']))
            {
                $score6 += 3;
            }
            // 金火成相+5
            if (isset($tp_planet[3]['phase']['3-4']))
            {
                $score6 += 5;
            }
            // 月亮与金星成相+5
            if (isset($tp_planet[1]['phase']['1-3']))
            {
                $score6 += 5;
                // 月亮过5宫+5
                if ($tp_planet[1]['in_house_id'] == 5)
                {
                    $score6 += 5;
                }
            }
        }
        // 计算星级
        $level = $this->modLevel5(floor($score6 / 10));

        if ($level > 0)
        {
            $temp = [
                'flag' => '0-7',
                'level' => $level,
            ];
            // 有夫之妇
            if ($source['sex'] == 1) $temp['flag'] = '0-9';

            $result[] = $temp;
        }

        //痛并快乐着
        $score7 = $level = 0;
        //tp日金合，且火土同时与日金之一成相+10
        if (
            isset($tp_planet[0]['phase']['0-3']) && $tp_planet[0]['phase']['0-3']['phase_e'] == 0
            &&
            ((isset($tp_planet[4]['phase']['4-3']) && isset($tp_planet[6]['phase']['6-3']))
                || (isset($tp_planet[4]['phase']['4-3']) && isset($tp_planet[6]['phase']['6-3'])))
        )
        {
            $score7 += 10;
            // 海王与日金之一成相+5
            if (isset($tp_planet[8]['phase']['8-0']) || isset($tp_planet[8]['phase']['8-3']))
            {
                $score7 += 5;
            }
            // 金在12宫或火土之一在12宫+10
            if ($tp_planet[3]['in_house_id'] == 12
                || $tp_planet[4]['in_house_id'] == 12
                || $tp_planet[6]['in_house_id'] == 12)
            {
                $score7 += 10;
            }
            // 冥王与日金之一成相+10
            if (isset($tp_planet[9]['phase']['9-0']) || isset($tp_planet[9]['phase']['9-3']))
            {
                $score7 += 10;
            }
            // 木星与日金之一成相+10
            if (isset($tp_planet[5]['phase']['5-0']) || isset($tp_planet[5]['phase']['5-3']))
            {
                $score7 += 10;
            }
        }
        // 计算星级
        $level = $this->modLevel5(floor($score7 / 10));

        if ($level > 0)
        {
            $temp = [
                'flag' => '0-8',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        return $result;
    }

    /**
     * 事业主题
     * @param array $source
     * @return array
     */
    public function getCareerTopic($source = [])
    {
        $result = [];

        $CaclByTopic = new CaclByTopic();
        // 10为征象宫
        // 太阳为征象星
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet3 = $CaclByTopic->init($source, ['target' => 3, 'house' => [10], 'planet' => 0]);
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [10], 'planet' => 0]);
        $planet5 = $CaclByTopic->init($source, ['target' => 5, 'house' => [10], 'planet' => 0]);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [10], 'planet' => 0]);
        $planet7 = $CaclByTopic->init($source, ['target' => 7, 'house' => [10], 'planet' => 0]);
        $planet8 = $CaclByTopic->init($source, ['target' => 8, 'house' => [10], 'planet' => 0]);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [10], 'planet' => 0]);

        // 事业主题
        //  人生得意须尽欢
        //      金星影响+木星影响之和大于火土天海冥破坏之和的两倍；按金木影响之和取星级
        $influ_35 = $planet3['relation'] + $planet5['relation'];
        $destory_46789 = $planet4['destory'] + $planet6['destory'] + $planet7['destory'] + $planet8['destory'] + $planet9['destory'];
        $cond1 = $influ_35 > ($destory_46789 * 2);
        if ($cond1)
        {
            $score = $influ_35;
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-1',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  激流勇进
        //      火星的成就值大于10，且，木星的成就值大于10；按火星成就值取星级
        if ($planet4['achievement'] >= 10 && $planet5['achievement'] >= 10)
        {
            $score = $planet4['achievement'];
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-2',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  办公室轰炸进行时
        //      火星的破坏值大于10
        // 改为15
        if ($planet4['destory'] >= 15)
        {
            $score = $planet4['destory'];
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  迷失方向的鸟
        //      海王的破坏值大于10，且无人生得意须尽欢
        // 改为15
        if ($planet8['destory'] >= 15 && !$cond1)
        {
            $score = $planet8['destory'];
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-4',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  异动不安的心（结束与开始）
        //      天王破坏大于10，且无人生得意须尽欢
        if ($planet9['destory'] >= 10 && !$cond1)
        {
            $score = $planet9['destory'];
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-5',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  希望与转机
        //      天王影响大于10，木星成就大于10，且火土海冥破坏之和小于10；按木天之和除以2定星级
        // 火土海冥破坏之和的限制去除
//        $destory_4689 = $planet4['destory'] + $planet6['destory'] + $planet8['destory'] + $planet9['destory'];
        if ($planet7['relation'] >= 10 && $planet5['achievement'] >= 10)
        {
            $score = ($planet7['achievement'] + $planet7['achievement']) / 2;
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-6',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  毁灭与新生
        //      冥王破坏大于10，且无人生得意须尽欢；按冥王取星级
        if ($planet9['destory'] >= 10 && !$cond1)
        {
            $score = $planet9['destory'];
            // 计算星级
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-7',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  泰山压顶不变色
        //      土星破坏大于10 且 影响(火木土天海冥)最高，或土星影响大于20；无人生得意须尽欢；按土星 取星级
        $influs = [$planet4['relation'], $planet5['relation'], $planet6['relation'], $planet7['relation'], $planet8['relation'], $planet9['relation'],];
        if (!$cond1 && ($planet6['relation'] >= 20 || ($planet6['relation'] >= 10 && $planet6['relation'] == max($influs))))
        {
            if ($planet6['relation'] == max($influs))
            {
                $score = $planet6['destory'];
                $level = $this->modLevel5(floor($score / 10));
            } else
            {
                $score = $planet6['destory'];
                $level = $this->modLevel5(floor(($score - 10) / 10));
            }
            if ($level > 0)
            {
                $temp = [
                    'flag' => '1-8',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        return $result;
    }

    /**
     * 健康主题
     * @param array $source
     * @return array
     */
    public function getHealthTopic($source = [])
    {
        $result = [];

        $CaclByTopic = new CaclByTopic();
        // 1/6为征象宫
        // 月亮为征象星
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [1, 6], 'planet' => 1]);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [1, 6], 'planet' => 1]);
        $planet8 = $CaclByTopic->init($source, ['target' => 8, 'house' => [1, 6], 'planet' => 1]);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [1, 6], 'planet' => 1]);

        $destorys = [$planet4['destory'], $planet6['destory'], $planet8['destory'], $planet9['destory']];
        $max_destorys = max($destorys);
        $sum_destorys = array_sum($destorys);

        //  疲惫苦闷，慢病折磨
        //      土星破坏度高于10且最高；或土星破坏度高于20
        $cond1 = ($planet6['destory'] >= 10 && $planet6['destory'] == $max_destorys && $sum_destorys >= 10);
        $cond2 = ($planet6['destory'] >= 20);
        if ($cond1 || $cond2)
        {
            if ($cond1)
            {
                $score = $planet6['destory'];
                $level = $this->modLevel5(floor($score / 10));
            } else
            {
                $score = $planet6['destory'];
                $level = $this->modLevel5(floor(($score - 10) / 10));
            }

            if ($level > 0)
            {
                $temp = [
                    'flag' => '2-1',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  跌打损伤，发炎上火
        //      火星破坏度高于10且最高；或火星破坏度高于20
        $cond1 = ($planet4['destory'] >= 10 && $planet4['destory'] == $max_destorys && $sum_destorys >= 10);
        $cond2 = ($planet4['destory'] >= 20);
        if ($cond1 || $cond2)
        {
            $score = $planet4['destory'];
            if ($cond1)
            {
                $level = $this->modLevel5(floor($score / 10));
            } else
            {
                $level = $this->modLevel5(floor(($score - 10) / 10));
            }

            if ($level > 0)
            {
                $temp = [
                    'flag' => '2-2',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  过敏虚弱，精神困惑
        //      海王星破坏度高于10且最高；或海王破坏度高于20
        $cond1 = ($planet8['destory'] >= 10 && $planet8['destory'] == $max_destorys && $sum_destorys >= 10);
        $cond2 = ($planet8['destory'] >= 20);
        if ($cond1 || $cond2)
        {
            $score = $planet8['destory'];
            if ($cond1)
            {

                $level = $this->modLevel5(floor($score / 10));
            } else
            {
                $level = $this->modLevel5(floor(($score - 10) / 10));
            }
            if ($level > 0)
            {
                $temp = [
                    'flag' => '2-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  检查身体，早做预防
        //      冥王星影响力高于10
        // 改为15
        if ($planet9['relation'] >= 15)
        {
            $score = $planet9['relation'];
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '2-4',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  敲响健康的警钟
        //      火土海冥破坏力之和大于20，或火土海冥影响力之合大于30
        // 20 改为25 30 改为35
        $relations = [$planet4['relation'], $planet6['relation'], $planet8['relation'], $planet9['relation']];
        $destorys_sum = array_sum($destorys);
        $relations_sum = array_sum($relations);
        $cond1 = $destorys_sum >= 25;
        $cond2 = $relations_sum >= 35;
        if ($cond1 || $cond2)
        {
            if ($cond1)
            {
                $score = $destorys_sum;
                $level = $this->modLevel5(floor(($destorys_sum - 10) / 10));
            } else
            {
                $score = $relations_sum;
                $level = $this->modLevel5(floor(($relations_sum - 20) / 10));
            }
            if ($level > 0)
            {
                $temp = [
                    'flag' => '2-5',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        return $result;
    }

    /**
     * 财富主题
     * @param array $source
     * @return array
     */
    public function getTreasureTopic($source = [])
    {
        $result = [];

        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        $natal = $source['natal_data']['planets'];// 本命盘

        // 掐着手指头过日子
        $score = 0;
        if (isset($tp_planet[3]['phase']['3-6']))
        {
            // 刑冲10合8拱六分5
            switch ($tp_planet[3]['phase']['3-6']['phase_e'])
            {
                case 0:
                    $score += 8;
                    break;
                case 60:
                    $score += 5;
                    break;
                case 90:
                    $score += 10;
                    break;
                case 120:
                    $score += 5;
                    break;
                case 180:
                    $score += 10;
                    break;
                default :
                    $score += 0;
                    break;
            }
        }
        // 土2宫5
        if ($tp_planet[6]['in_house_id'] == 2)
        {
            $score += 5;
            // 月土（土在2宫）
            if (isset($tp_planet[1]['phase']['1-6']))
            {
                // 刑冲5合3拱六分2
                switch ($tp_planet[1]['phase']['1-6']['phase_e'])
                {
                    case 0:
                        $score += 3;
                        break;
                    case 60:
                        $score += 2;
                        break;
                    case 90:
                        $score += 5;
                        break;
                    case 120:
                        $score += 2;
                        break;
                    case 180:
                        $score += 5;
                        break;
                    default :
                        $score += 0;
                        break;
                }
            }
        }
        // 本命无金木且不是金射手金双鱼
        if (!isset($natal[3]['phase']['3-5']) && !in_array($natal[3]['in_sign_id'], [9, 12]))
        {
            if (isset($natal[3]['phase']['3-6']))
            {
                // 金土合刑冲+4拱六分+2
                switch ($natal[3]['phase']['3-6']['phase_e'])
                {
                    case 0:
                        $score += 4;
                        break;
                    case 60:
                        $score += 2;
                        break;
                    case 90:
                        $score += 4;
                        break;
                    case 120:
                        $score += 2;
                        break;
                    case 180:
                        $score += 4;
                        break;
                    default :
                        $score += 0;
                        break;
                }
            }
            // 金星摩羯且无金火金海+2
            if ($natal[3]['in_sign_id'] == 10
                && !isset($natal[3]['phase']['3-4'])
                && !isset($natal[3]['phase']['3-8']))
            {
                $score += 2;
            }
        }
        // tr土刑冲合金星+10
        if (isset($tr_planet1[6]['phase']['6-3']))
        {
            switch ($tr_planet1[6]['phase']['6-3']['phase_e'])
            {
                case 0:
                    $score += 10;
                    break;
                case 60:
                    $score += 0;
                    break;
                case 90:
                    $score += 10;
                    break;
                case 120:
                    $score += 0;
                    break;
                case 180:
                    $score += 10;
                    break;
                default :
                    $score += 0;
                    break;
            }
        }
        // tr土星过2宫且本命无金木金火日金相位+7
        if ($tr_planet1[6]['in_house_id'] == 2 && !isset($natal[3]['phase']['3-0'])
            && !isset($natal[3]['phase']['3-4']) && !isset($natal[3]['phase']['3-5']))
        {
            $score += 7;
        }
        $level = $this->modLevel5(floor($score / 10));

        if ($level >= 1)
        {
            $temp = [
                'flag' => '3-1',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        //  富婆（阔少爷）的幸福生活
        $score = 0;
        // tp金土不成相且  土星  不在1/2宫  不合轴  不与日月刑冲合
        if (!isset($tp_planet[3]['phase']['3-6']) && !in_array($tp_planet[6]['in_house_id'], [1, 2])
            && (!isset($tp_planet[6]['phase']['6-' . ASC])
                || !in_array($tp_planet[6]['phase']['6-' . ASC]['phase_e'], [0, 180]))
            && (!isset($tp_planet[6]['phase']['6-' . MC])
                || !in_array($tp_planet[6]['phase']['6-' . MC]['phase_e'], [0, 180]))
            && (!isset($tp_planet[6]['phase']['6-0'])
                || !in_array($tp_planet[6]['phase']['6-0']['phase_e'], [0, 90, 180]))
            && (!isset($tp_planet[6]['phase']['6-1'])
                || !in_array($tp_planet[6]['phase']['6-1']['phase_e'], [0, 90, 180]))
        )
        {
            // tp金木成相+10
            if (isset($tp_planet[3]['phase']['3-5']))
            {
                $score += 10;
                // 日金或日木成相+10
                if (isset($tp_planet[0]['phase']['0-3']) || isset($tp_planet[0]['phase']['0-5']))
                {
                    $score += 10;
                }
                // 金星或木星合轴+10
                if ((!isset($tp_planet[3]['phase']['3-' . ASC])
                        || !in_array($tp_planet[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                    || (!isset($tp_planet[3]['phase']['3-' . MC])
                        || !in_array($tp_planet[3]['phase']['3-' . MC]['phase_e'], [0, 180]))
                    || (!isset($tp_planet[5]['phase']['5-' . ASC])
                        || !in_array($tp_planet[5]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                    || (!isset($tp_planet[5]['phase']['5-' . MC])
                        || !in_array($tp_planet[5]['phase']['5-' . MC]['phase_e'], [0, 180])))
                {
                    $score += 10;
                }
                // 月亮与金或木成非刑相+10
                if ((isset($tp_planet[1]['phase']['1-3']) && $tp_planet[1]['phase']['1-3']['phase_e'] != 90)
                    || (isset($tp_planet[1]['phase']['1-5']) && $tp_planet[1]['phase']['1-5']['phase_e'] != 90))
                {
                    $score += 10;
                }
                // 月亮在1/5/7/9/11宫+5
                if (in_array($tp_planet[1]['in_house_id'], [1, 5, 7, 9, 11]))
                {
                    $score += 5;
                }
                // 本命金木成相+10
                if (isset($natal[3]['phase']['3-5']))
                {
                    $score += 10;
                }
            }
        }

        $level = $this->modLevel5(floor($score / 10));

        if ($level >= 1)
        {
            if ($source['sex'] == 1) $flag = '3-6';
            else $flag = '3-2';

            $temp = [
                'flag' => $flag,
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  飘飘忽忽钱没了 全部计算tp数据
        $score = $score1 = $score2 = 0;
        // 海王
        if (!empty($tp_planet[8]['phase']))
        {
            foreach ($tp_planet[8]['phase'] as $phase)
            {
                // 海王有一个刑冲相位，相位一端在2宫+5
                if ($tp_planet[$phase['id']]['in_house_id'] == 2 && in_array($phase['phase_e'], [90, 180]))
                {
                    $score1 += 5;
                }
                // 海王与金星合刑冲+5
                if ($phase['id'] == 3 && in_array($phase['phase_e'], [0, 90, 180]))
                {
                    $score1 += 5;
                    // 海王在2宫+5
                    if ($tp_planet[8]['in_house_id'] == 2)
                    {
                        $score1 += 5;
                    }
                }
                // 海王与水星或太阳成相+5
                if (in_array($phase['id'], [0, 2]))
                {
                    $score1 += 5;
                }
                // 海王合轴+5
                if (in_array($phase['id'], [ASC, MC]) && in_array($phase['phase_e'], [0, 180]))
                {
                    $score1 += 5;
                }
            }
        }
        // 金星
        if (!empty($tp_planet[3]['phase']))
        {
            $p3_phase68_90180_num = 0;
            $p3_phase_4689_0_num = 0;
            $p3_phase_4689_num = 0;
            foreach ($tp_planet[3]['phase'] as $phase)
            {

                if (in_array($phase['id'], [4, 6, 8, 9]))
                {
                    // 金星与土海刑冲
                    if (in_array($phase['id'], [6, 8]) && in_array($phase['phase_e'], [90, 180]))
                    {
                        $p3_phase68_90180_num++;
                    }
                    // 金星与火土海冥合相
                    if ($phase['phase_e'] == 0)
                    {
                        $p3_phase_4689_0_num++;
                    }
                    // 金与火土天海冥成相
                    $p3_phase_4689_num++;
                }
            }
            // 金星至少与土海之一有刑冲，且与火土天海冥之一合相+5
            if ($p3_phase68_90180_num >= 1 && $p3_phase_4689_0_num >= 1)
            {
                $score2 += 5;
            }
            // 金与火土天海冥之中两个以上成相，每多一个+2
            if ($p3_phase_4689_num >= 2)
            {
                $score2 += ($p3_phase_4689_num - 2) * 2;
            }
            // 金星在12宫+3
            if ($tp_planet[3]['in_house_id'] == 12)
            {
                $score2 += 3;
            }
        }
        // 以上两项均有得分，且海王得分超过10生效
        if ($score1 >= 10 && $score2 > 0)
        {
            $score = $score1 + $score2;
            // 月亮与海王刑冲+5
            if (isset($tp_planet[1]['phase']['1-8']) && in_array($tp_planet[1]['phase']['1-8']['phase_e'], [90, 180]))
            {
                $score += 5;
            }
            // 月亮与火土天冥刑冲+3
            if (isset($tp_planet[1]['phase']['1-4']) && in_array($tp_planet[1]['phase']['1-4']['phase_e'], [90, 180]))
            {
                $score += 3;
            }
            if (isset($tp_planet[1]['phase']['1-6']) && in_array($tp_planet[1]['phase']['1-6']['phase_e'], [90, 180]))
            {
                $score += 3;
            }
            if (isset($tp_planet[1]['phase']['1-7']) && in_array($tp_planet[1]['phase']['1-7']['phase_e'], [90, 180]))
            {
                $score += 3;
            }
            if (isset($tp_planet[1]['phase']['1-9']) && in_array($tp_planet[1]['phase']['1-9']['phase_e'], [90, 180]))
            {
                $score += 3;
            }
            // 月亮在2宫或8宫被任意星刑冲+5
            if (in_array($tp_planet[1]['in_house_id'], [2, 8]))
            {
                $p1_phase_90180 = false;
                if (!empty($tp_planet[1]['phase']))
                {
                    foreach ($tp_planet[1]['phase'] as $phase)
                    {
                        // 被任意星刑冲
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            $p1_phase_90180 = true;
                            break;
                        }
                    }
                }
                if ($p1_phase_90180 === true)
                {
                    $score += 5;
                }
            }
            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '3-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        $cond1 = $cond2 = [];
        //  天上掉馅饼（不满足破财）
        $score = $score1 = $score2 = 0;
        //金星
        // 金星木星成相5
        if (isset($tp_planet[3]['phase']['3-5']))
        {
            $score1 += 5;
            // 金天或木天成相5
            if (isset($tp_planet[3]['phase']['3-7']) || isset($tp_planet[5]['phase']['5-7']))
            {
                $score1 += 5;
            }
            // 日木成相5
            if (isset($tp_planet[0]['phase']['0-5']))
            {
                $score1 += 5;
            }
            // 金星合轴或木星合轴5
            if ((isset($tp_planet[3]['phase']['3-' . ASC]) && in_array($tp_planet[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[3]['phase']['3-' . MC]) && in_array($tp_planet[3]['phase']['3-' . MC]['phase_e'], [0, 180]))
                || (isset($tp_planet[3]['phase']['5-' . ASC]) && in_array($tp_planet[3]['phase']['5-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[3]['phase']['5-' . MC]) && in_array($tp_planet[3]['phase']['5-' . MC]['phase_e'], [0, 180])))
            {
                $score1 += 5;
            }
            // 金星或木星在2/8宫5
            if (in_array($tp_planet[3]['in_house_id'], [2, 8]) || in_array($tp_planet[5]['in_house_id'], [2, 8]))
            {
                $score1 += 5;
            }
        }
        // 日金合5
        if (isset($tp_planet[0]['phase']['0-3']) && $tp_planet[0]['phase']['0-3']['phase_e'] == 0)
        {
            $score += 5;
            // 金星合轴5
            if ((isset($tp_planet[3]['phase']['3-' . ASC]) && in_array($tp_planet[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[3]['phase']['3-' . MC]) && in_array($tp_planet[3]['phase']['3-' . MC]['phase_e'], [0, 180])))
            {
                $score += 5;
            }
            // 金星在2/8宫5
            if (in_array($tp_planet[3]['in_house_id'], [2, 8]))
            {
                $score += 5;
            }
        }
        // 金火合且不在6/12宫3
        if (!in_array($tp_planet[3]['in_house_id'], [6, 12])
            && !in_array($tp_planet[4]['in_house_id'], [6, 12])
            && isset($tp_planet[3]['phase']['3-4'])
            && $tp_planet[3]['phase']['3-4']['phase_e'] == 0)
        {
            $score += 3;
        }
        // 金星被土星刑冲-20
        if (isset($tp_planet[3]['phase']['3-6']) && in_array($tp_planet[3]['phase']['3-6']['phase_e'], [90, 180]))
        {
            $score += -20;
        }
        // 金星被海王刑冲-10
        if (isset($tp_planet[3]['phase']['3-8']) && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180]))
        {
            $score += -10;
        }
        //月亮
        // 月亮2/8宫+2
        if (in_array($tp_planet[1]['in_house_id'], [2, 8]))
        {
            $score2 += 2;
            // 与木成相但不与金成相3
            if (isset($tp_planet[1]['phase']['1-5']) && !isset($tp_planet[1]['phase']['1-3']))
            {
                $score2 += 3;
            } // 与金成相但不与木成相3
            elseif (!isset($tp_planet[1]['phase']['1-5']) && isset($tp_planet[1]['phase']['1-3']))
            {
                $score2 += 3;
            } // 金木同时成相8
            elseif (isset($tp_planet[1]['phase']['1-5']) && isset($tp_planet[1]['phase']['1-3']))
            {
                $score2 += 8;
            }
            // 月土刑冲-10
            if (isset($tp_planet[1]['phase']['1-6']) && in_array($tp_planet[1]['phase']['1-6']['phase_e'], [90, 180]))
            {
                $score2 += -10;
            }
        }
        $score = $score1 + $score2;
        // 以上两条同时有得分且相加过10生效
        if ($score1 > 0 && $score2 > 0 && $score > 10)
        {
            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $cond1 = [
                    'flag' => '3-4',
                    'level' => $level,
                ];
            }
        }

        //  破财未必免灾（不满足馅饼）
        $score = $score1 = $score2 = $score3 = 0;
        //金星刑冲
        //  金星天王刑冲5
        if (isset($tp_planet[3]['phase']['3-7']) && in_array($tp_planet[3]['phase']['3-7']['phase_e'], [90, 180]))
        {
            $score1 += 5;
        }
        //  金星土星刑冲5
        if (isset($tp_planet[3]['phase']['3-6']) && in_array($tp_planet[3]['phase']['3-6']['phase_e'], [90, 180]))
        {
            $score1 += 5;
        }
        //  金星海王刑冲5
        if (isset($tp_planet[3]['phase']['3-8']) && in_array($tp_planet[3]['phase']['3-8']['phase_e'], [90, 180]))
        {
            $score1 += 5;
        }
        //  金星火星刑冲5
        if (isset($tp_planet[3]['phase']['3-4']) && in_array($tp_planet[3]['phase']['3-4']['phase_e'], [90, 180]))
        {
            $score1 += 5;
        }
        //  金星冥王刑冲3
        if (isset($tp_planet[3]['phase']['3-9']) && in_array($tp_planet[3]['phase']['3-9']['phase_e'], [90, 180]))
        {
            $score1 += 3;
        }
        //  12宫土或海与金星成相5
        if (($tp_planet[6]['in_house_id'] == 12 && isset($tp_planet[3]['phase']['3-6']))
            || ($tp_planet[8]['in_house_id'] == 12 && isset($tp_planet[3]['phase']['3-8'])))
        {
            $score1 += 5;
        }
        //2宫不良
        if ($tp_planet[6]['in_house_id'] == 2)
        {
            $score2 += 5;
            // 火土同入5
            if ($tp_planet[4]['in_house_id'] == 2)
            {
                $score2 += 5;
            }
            // 土冥同入5
            if ($tp_planet[9]['in_house_id'] == 2)
            {
                $score2 += 5;
            }
        }
        $is_p8_phase_house2 = false;
        $is_p7_phase_house2_90180 = false;
        // 2宫宫内星
        if ($source['thirdprogressed_data']['houses'][2]['have_planet_num'] > 0)
        {
            foreach ($source['thirdprogressed_data']['houses'][2]['in_house_area_planet_info'] as $planet)
            {
                // 宫内星的相位
                $in_house_planet_phase = $tp_planet[$planet['id']]['phase'];
                // 刑冲凶
                // 土星刑冲2宫内星5
                if (isset($in_house_planet_phase[$planet['id'] . '-6'])
                    && in_array($in_house_planet_phase[$planet['id'] . '-6']['phase_e'], [90, 180]))
                {
                    $score2 += 5;
                    // 火星也刑冲该星10
                    // 火星与该星成非刑冲相5
                    if (isset($tp_planet[4]['phase']['4-' . $planet['id']]))
                    {
                        if (in_array($tp_planet[4]['phase']['4-' . $planet['id']]['phase_e'], [90, 180]))
                        {
                            $score2 += 10;
                        } else
                        {
                            $score2 += 5;
                        }
                    }
                    // 天海冥也刑冲该星7
                    // 天海冥与该星成非刑冲相4
                    if (isset($tp_planet[7]['phase']['7-' . $planet['id']]))
                    {
                        if (in_array($tp_planet[7]['phase']['7-' . $planet['id']]['phase_e'], [90, 180]))
                        {
                            $score2 += 10;
                        } else
                        {
                            $score2 += 5;
                        }
                    }
                    if (isset($tp_planet[8]['phase']['8-' . $planet['id']]))
                    {
                        if (in_array($tp_planet[8]['phase']['8-' . $planet['id']]['phase_e'], [90, 180]))
                        {
                            $score2 += 10;
                        } else
                        {
                            $score2 += 5;
                        }
                    }
                    if (isset($tp_planet[9]['phase']['9-' . $planet['id']]))
                    {
                        if (in_array($tp_planet[9]['phase']['9-' . $planet['id']]['phase_e'], [90, 180]))
                        {
                            $score2 += 10;
                        } else
                        {
                            $score2 += 5;
                        }
                    }
                }
                // 火天或火海同时刑冲2宫内星10
                if (isset($in_house_planet_phase[$planet['id'] . '-4'])
                    && in_array($in_house_planet_phase[$planet['id'] . '-4']['phase_e'], [90, 180]))
                {
                    if ((isset($in_house_planet_phase[$planet['id'] . '-7'])
                            && in_array($in_house_planet_phase[$planet['id'] . '-7']['phase_e'], [90, 180]))
                        || (isset($in_house_planet_phase[$planet['id'] . '-8'])
                            && in_array($in_house_planet_phase[$planet['id'] . '-8']['phase_e'], [90, 180])))
                    {
                        $score2 += 10;
                    }
                }
                // 天海同时刑冲2宫内星5
                if (isset($in_house_planet_phase[$planet['id'] . '-7'])
                    && in_array($in_house_planet_phase[$planet['id'] . '-7']['phase_e'], [90, 180])
                    && isset($in_house_planet_phase[$planet['id'] . '-8'])
                    && in_array($in_house_planet_phase[$planet['id'] . '-8']['phase_e'], [90, 180]))
                {
                    $score2 += 5;
                }
                // 海与2宫宫内星成相
                if (isset($in_house_planet_phase[$planet['id'] . '-8']))
                {
                    $is_p8_phase_house2 = true;
                }
                // 天与2宫宫内星刑冲
                if (isset($in_house_planet_phase[$planet['id'] . '-7'])
                    && in_array($in_house_planet_phase[$planet['id'] . '-7']['phase_e'], [90, 180]))
                {
                    $is_p7_phase_house2_90180 = true;
                }
            }
        }
        // 12宫
        // 12宫内有土或海与2宫宫内星成相+5
        if ($tp_planet[6]['in_house_id'] == 12 || $is_p8_phase_house2)
        {
            $score2 += 5;
        }
        //月亮激活
        //  月亮与2/8宫宫内星刑冲+5
        //      此时与火土冥海每一个形成刑冲+5
        //      此时若还与2/8宫宫内星成非刑冲相+5
        if (!empty($tp_planet[1]['phase']))
        {
            $p1_phase_house28_90180_num = 0;
            foreach ($tp_planet[1]['phase'] as $phase)
            {
                // 月亮与2/8宫宫内星刑冲+5
                if (in_array($phase['phase_e'], [90, 180]) && in_array($tp_planet[$phase['id']]['in_house_id'], [2, 8]))
                {
                    $score3 += 5;

                    $p1_phase_house28_90180_num++;
                }
            }
            // 此时与火土冥海每一个形成刑冲+5
            if ($p1_phase_house28_90180_num > 0 && isset($tp_planet[1]['phase']['1-7'])
                && in_array($tp_planet[1]['phase']['1-7']['phase_e'], [90, 180]))
            {
                $score3 += 5;
            }
            if ($p1_phase_house28_90180_num > 0 && isset($tp_planet[1]['phase']['1-8'])
                && in_array($tp_planet[1]['phase']['1-8']['phase_e'], [90, 180]))
            {
                $score3 += 5;
            }
            if ($p1_phase_house28_90180_num > 0 && isset($tp_planet[1]['phase']['1-9'])
                && in_array($tp_planet[1]['phase']['1-9']['phase_e'], [90, 180]))
            {
                $score3 += 5;
            }
            // 此时若还与2/8宫宫内星成非刑冲相+5
            if ($p1_phase_house28_90180_num > 1)
            {
                $score3 += 5;
            }
        }
        // 以上三项均有得分才生效，
        if ($score1 > 0 && $score2 > 0 && $score3 > 0)
        {
            $score = $score1 + $score2 + $score3;
            // 若此时满足以下条件之一+5
            //  天王与金星成相位
            //  天王落2/8宫
            //  天王刑冲2宫宫内星
            //  月亮与天王成相
            if (isset($tp_planet[7]['phase']['7-3'])
                || in_array($tp_planet[7]['in_house_id'], [2, 8])
                || $is_p7_phase_house2_90180
                || isset($tp_planet[7]['phase']['7-1']))
            {
                $score += 5;
            }
            //特殊情形（独立计算）
            //  金星与火土天海之一刑冲，且与火土天海冥之一合相，且金月合刑冲或月在2宫与土天海之一成相，且月木不成相+10

            // 金星与火土天海刑冲数量
            $p3_phase4678_90180_num = 0;
            // 金星与火土天海冥合相数量
            $p3_phase46789_0_num = 0;
            // 金星与火土天海冥成相数量
            $p3_phase46789_num = 0;
            $is_p3_or_phase_house = false;
            if (!empty($tp_planet[3]['phase']))
            {
                foreach ($tp_planet[3]['phase'] as $phase)
                {
                    if (in_array($phase['id'], [4, 6, 7, 8]) && in_array($phase['phase_e'], [90, 180]))
                    {
                        $p3_phase4678_90180_num++;
                    }
                    if (in_array($phase['id'], [4, 6, 7, 8, 9]))
                    {
                        $p3_phase46789_num++;
                        if (in_array($phase['phase_e'], [0]))
                        {
                            $p3_phase46789_0_num++;
                        }
                    }
                    if ($tp_planet[3]['in_house_id'] == 2 || $tp_planet[$phase['id']]['in_house_id'] == 2)
                    {
                        $is_p3_or_phase_house = true;
                    }
                }
            }
            if ($p3_phase4678_90180_num >= 1 && $p3_phase46789_0_num >= 1
                && !isset($tp_planet[1]['phase']['1-5'])
                &&
                (
                    (isset($tp_planet[3]['phase']['3-1']) && in_array($tp_planet[3]['phase']['3-1']['phase_e'], [0, 90, 180]))
                    || ($tp_planet[1]['in_house_id'] == 2 &&
                        (
                            isset($tp_planet[1]['phase']['1-6'])
                            || isset($tp_planet[1]['phase']['1-7'])
                            || isset($tp_planet[1]['phase']['1-8'])
                        ))
                )
            )
            {
                $score += 10;
                // 金星与刑冲星其一位于2/8宫+5
                if ($is_p3_or_phase_house)
                {
                    $score += 5;
                }
                // 金星与火土天海冥中三个或三个以上成相+5
                if ($p3_phase46789_num >= 3)
                {
                    $score += 5;
                }
            }
            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $cond2 = [
                    'flag' => '3-5',
                    'level' => $level,
                ];
            }
        }
        // 天上掉馅饼（不满足破财）
        if (!empty($cond1) && empty($cond2))
        {
            $result[] = $cond1;
        }// 破财未必免灾（不满足馅饼）
        elseif (empty($cond1) && !empty($cond2))
        {
            $result[] = $cond2;
        }

        return $result;
    }

    /**
     * 家庭主题
     * @param array $source
     * @return array
     */
    public function getFamilyTopic($source = [])
    {
        $result = [];

        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命

        $CaclByTopic = new CaclByTopic();
        // 4为征象宫
        // 月亮为征象星
        /**
         * 只计算行运内盘的月亮，三限、行运外盘不计算
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet3 = $CaclByTopic->init($source, ['target' => 3, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet5 = $CaclByTopic->init($source, ['target' => 5, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet7 = $CaclByTopic->init($source, ['target' => 7, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet8 = $CaclByTopic->init($source, ['target' => 8, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [4], 'planet' => 1, 'planet_type' => 'tr2']);

        //  家有喜事
        //      金木的成就值之和大于10，且火土冥海的破坏值之和小于10
        $score = $planet3['achievement'] + $planet5['achievement'];
        if ($score >= 10 && ($planet4['destory'] + $planet6['destory'] + $planet8['destory'] + $planet9['destory']) < 10)
        {
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '4-1',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  团圆小时光
        //      tr金水木之一与本命月亮成非刑相（如有两个+14分）
        $score = 0;
        $p235_phase1_no90_num = 0;
        if (!empty($tr_planet2[1]['phase']))
        {
            foreach ($tr_planet2[1]['phase'] as $phase)
            {
                if (in_array($phase['id'], [2, 3, 5]) && $phase['phase_e'] != 90)
                {
                    $p235_phase1_no90_num++;
                }
            }
        }
        if ($p235_phase1_no90_num >= 1)
        {
            if ($p235_phase1_no90_num >= 2)
            {
                $score += 14;
            }
            // 日金水过4宫与本命木金成非刑相+12
            if (($tr_planet1[0]['in_house_id'] == 4 && (
                        (isset($tr_planet1[0]['phase']['0-3']) && $tr_planet1[0]['phase']['0-3']['phase_e'] != 90)
                        || (isset($tr_planet1[0]['phase']['0-5']) && $tr_planet1[0]['phase']['0-5']['phase_e'] != 90)))
                || ($tr_planet1[0]['in_house_id'] == 4 && (
                        (isset($tr_planet1[0]['phase']['0-3']) && $tr_planet1[0]['phase']['0-3']['phase_e'] != 90)
                        || (isset($tr_planet1[0]['phase']['0-5']) && $tr_planet1[0]['phase']['0-5']['phase_e'] != 90)))
                || ($tr_planet1[0]['in_house_id'] == 4 && (
                        (isset($tr_planet1[0]['phase']['0-3']) && $tr_planet1[0]['phase']['0-3']['phase_e'] != 90)
                        || (isset($tr_planet1[0]['phase']['0-5']) && $tr_planet1[0]['phase']['0-5']['phase_e'] != 90)))
            )
            {
                $score += 12;
            }
            // 金过4宫与本命日月水成非刑相+12
            if ($tr_planet1[3]['in_house_id'] == 4
                && ((isset($tr_planet1[3]['phase']['3-0']) && $tr_planet1[3]['phase']['3-0']['phase_e'] != 90)
                    || (isset($tr_planet1[3]['phase']['3-1']) && $tr_planet1[3]['phase']['3-1']['phase_e'] != 90)
                    || (isset($tr_planet1[3]['phase']['3-2']) && $tr_planet1[3]['phase']['3-2']['phase_e'] != 90))
            )
            {
                $score += 12;
            }
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '4-2',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  请个菩萨保平安
        //      火土海冥破坏之和大于20
        // 改为30
        $destory_4689 = $planet4['destory'] + $planet6['destory'] + $planet8['destory'] + $planet9['destory'];
        if ($destory_4689 >= 30)
        {
            $score = $destory_4689;

            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '4-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //  宅子里的硝烟
        //      火星影响大于8，且天王影响大于8
        if ($planet4['relation'] >= 8 && $planet7['relation'] >= 8)
        {
            $score = $planet4['relation'] + $planet7['relation'];
            $level = $this->modLevel5(floor($score / 10));
            if ($level > 0)
            {
                $temp = [
                    'flag' => '4-4',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }


        return $result;
    }

    /**
     * 交际主题
     * @param array $source
     * @return array
     */
    public function getContactTopic($source = [])
    {
        $result = [];

        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘

        $CaclByTopic = new CaclByTopic();

        //交际主题
        //  装在壳子里的人
        $score = 0;
        //土星
        // 金星土星成相+5
        if (isset($tp_planet[3]['phase']['3-6']))
        {
            $score += 5;
            // 日土成相+5
            if (isset($tp_planet[0]['phase']['0-6']))
            {
                $score += 5;
            }
            // 土星或天王合轴+5
            if (isset($tp_planet[6]['phase']['6-' . ASC]) && in_array($tp_planet[6]['phase']['6-' . ASC]['phase_e'], [0, 180])
                || isset($tp_planet[6]['phase']['6-' . MC]) && in_array($tp_planet[6]['phase']['6-' . MC]['phase_e'], [0, 180])
                || isset($tp_planet[7]['phase']['7-' . ASC]) && in_array($tp_planet[7]['phase']['7-' . ASC]['phase_e'], [0, 180])
                || isset($tp_planet[7]['phase']['7-' . MC]) && in_array($tp_planet[7]['phase']['7-' . MC]['phase_e'], [0, 180]))
            {
                $score += 5;
            }
        }
        //月亮
        // tp月亮过4/8/12宫+5
        if (in_array($tp_planet[1]['in_house_id'], [4, 8, 12]))
        {
            $score += 5;
            //  月土成相+5
            if (isset($tp_planet[1]['phase']['1-6']))
            {
                $score += 5;
            }
            //  月冥成相+5
            if (isset($tp_planet[1]['phase']['1-9']))
            {
                $score += 5;
            }
            //  tr月亮过4/8/12宫+5
            if (in_array($tr_planet1[1]['in_house_id'], [4, 8, 12]))
            {
                $score += 5;
            }
            //  tr金土成相+5
            if (isset($tr_planet1[3]['phase']['3-6']))
            {
                $score += 5;
            }
            //  月亮与金星或木星成相-10
            if (isset($tp_planet[1]['phase']['1-3']) || isset($tp_planet[1]['phase']['1-5']))
            {
                $score += -10;
            }
        }
        // 月木、日木、金木、水木、不能成相，木星不合轴
        if (!isset($tp_planet[1]['phase']['1-5']) && !isset($tp_planet[0]['phase']['0-5'])
            && !isset($tp_planet[3]['phase']['3-5']) && !isset($tp_planet[2]['phase']['2-5'])
            && (!isset($tp_planet[5]['phase']['5-' . ASC]) || !in_array($tp_planet[5]['phase']['5-' . ASC]['phase_e'], [0, 180]))
            && (!isset($tp_planet[5]['phase']['5-' . MC]) || !in_array($tp_planet[5]['phase']['5-' . MC]['phase_e'], [0, 180]))
        )
        {
            //  月亮不与金水成相+5
            if (!isset($tp_planet[1]['phase']['1-3']) && !isset($tp_planet[1]['phase']['1-2']))
            {
                $score += 5;
            }
            //  月亮过4/8宫+5
            if (in_array($tp_planet[1]['in_house_id'], [4, 8]))
            {
                $score += 5;
            }
            //  月亮过12宫+8
            if (in_array($tp_planet[1]['in_house_id'], [12]))
            {
                $score += 8;
            }
            //  金土成相+5
            if (isset($tp_planet[3]['phase']['3-6']))
            {
                $score += 5;
            }
        }
        $level = $this->modLevel5(floor($score / 10));
        if ($level >= 1)
        {
            $temp = [
                'flag' => '5-1',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        //  与全世界对话
        // 20181223 与全世界对话，主题名改为 喧闹与升腾，条件中的5分替换为8分，15分替换为20分
        //      金/木/水对9/10/11的影响力都大于5，土星影响力小于15
        $score = 0;
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet2 = $CaclByTopic->init($source, ['target' => 2, 'house' => [9, 10, 11], 'planet' => 999]);
        $planet3 = $CaclByTopic->init($source, ['target' => 3, 'house' => [9, 10, 11], 'planet' => 999]);
        $planet5 = $CaclByTopic->init($source, ['target' => 5, 'house' => [9, 10, 11], 'planet' => 999]);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [9, 10, 11], 'planet' => 999]);
        if ($planet2['relation'] >= 8 && $planet3['relation'] >= 8 && $planet5['relation'] >= 8 && $planet6['relation'] < 20)
        {
            $score = $planet2['relation'] + $planet3['relation'] + $planet5['relation'];

            $level = $this->modLevel5(floor($score / 20));
            if ($level >= 1)
            {
                $temp = [
                    'flag' => '5-2',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        //  朋友圈大地震
        //      主宫7/11
        //      主星金
        //      火星的破坏值大于8，且天王+冥王的破坏值之和大于8
        // 8改为15
        $score = 0;
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [7, 11], 'planet' => 3]);
        $planet7 = $CaclByTopic->init($source, ['target' => 7, 'house' => [7, 11], 'planet' => 3]);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [7, 11], 'planet' => 3]);
        if ($planet4['destory'] >= 15 && ($planet7['destory'] + $planet9['destory']) >= 15)
        {
            $score = $planet4['destory'] + $planet7['destory'] + $planet9['destory'];

            $level = $this->modLevel5(floor($score / 15));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '5-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        //  野百合也有春天
        //      主宫7
        //      主星金
        //      金木的影响力之合大于15，且火土天海冥破坏力之合小于10
        // 破坏力之和改为小于20
        $score = 0;
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet3 = $CaclByTopic->init($source, ['target' => 3, 'house' => [7], 'planet' => 3]);
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [7], 'planet' => 3]);
        $planet5 = $CaclByTopic->init($source, ['target' => 5, 'house' => [7], 'planet' => 3]);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [7], 'planet' => 3]);
        $planet7 = $CaclByTopic->init($source, ['target' => 7, 'house' => [7], 'planet' => 3]);
        $planet8 = $CaclByTopic->init($source, ['target' => 8, 'house' => [7], 'planet' => 3]);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [7], 'planet' => 3]);
        if (($planet3['relation'] + $planet5['relation']) >= 15
            && ($planet4['destory'] + $planet6['destory']
                + $planet7['destory'] + $planet8['destory'] + $planet9['destory']) < 20)
        {
            $score = $planet3['relation'] + $planet5['relation'];

            $level = $this->modLevel5(floor($score / 15));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '5-4',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        //吵闹与争议
        $score = 0;
        // tp水火刑冲+6（tp火在7刑太阳+6）
        if ((isset($tp_planet[2]['phase']['2-4'])
                && in_array($tp_planet[2]['phase']['2-4']['phase_e'], [90, 180]))
            || ($tp_planet[4]['in_house_id'] == 7 && isset($tp_planet[4]['phase']['4-0'])
                && in_array($tp_planet[4]['phase']['4-0']['phase_e'], [90]))
        )
        {
            $score += 6;
            //  tp月亮与水星或火星刑冲+8
            if ((isset($tp_planet[1]['phase']['1-2'])
                    && in_array($tp_planet[1]['phase']['1-2']['phase_e'], [90, 180]))
                || (isset($tp_planet[1]['phase']['1-4'])
                    && in_array($tp_planet[1]['phase']['1-4']['phase_e'], [90, 180])))
            {
                $score += 8;
            }
            //  tp月亮与水星或火星合+6
            if ((isset($tp_planet[1]['phase']['1-2'])
                    && in_array($tp_planet[1]['phase']['1-2']['phase_e'], [0]))
                || (isset($tp_planet[1]['phase']['1-4'])
                    && in_array($tp_planet[1]['phase']['1-4']['phase_e'], [0])))
            {
                $score += 6;
            }
            //  tp月亮在7/11被水火冥海刑冲+7
            if (in_array($tp_planet[1]['in_house_id'], [7, 11])
                && (
                    (isset($tp_planet[1]['phase']['1-2'])
                        && in_array($tp_planet[1]['phase']['1-2']['phase_e'], [0]))
                    || (isset($tp_planet[1]['phase']['1-4'])
                        && in_array($tp_planet[1]['phase']['1-4']['phase_e'], [0]))
                    || (isset($tp_planet[1]['phase']['1-8'])
                        && in_array($tp_planet[1]['phase']['1-8']['phase_e'], [0]))
                    || (isset($tp_planet[1]['phase']['1-9'])
                        && in_array($tp_planet[1]['phase']['1-9']['phase_e'], [0]))
                )
            )
            {
                $score += 7;
            }
            //  tr日火刑冲/火日刑冲/火月刑冲各+7
            if ((isset($tr_planet1[0]['phase']['0-4']))
            )
            {
                if (in_array($tr_planet1[0]['phase']['0-4']['phase_e'], [90, 180]))
                {
                    $score += 7;
                }// tr日火/火日/火月合拱六分各+5
                elseif (in_array($tr_planet1[0]['phase']['0-4']['phase_e'], [60, 120]))
                {
                    $score += 5;
                }
            }
            if ((isset($tr_planet1[4]['phase']['4-0']))
            )
            {
                if (in_array($tr_planet1[4]['phase']['4-0']['phase_e'], [90, 180]))
                {
                    $score += 7;
                }// tr日火/火日/火月合拱六分各+5
                elseif (in_array($tr_planet1[4]['phase']['4-0']['phase_e'], [60, 120]))
                {
                    $score += 5;
                }
            }
            if ((isset($tr_planet1[4]['phase']['4-1']))
            )
            {
                if (in_array($tr_planet1[4]['phase']['4-1']['phase_e'], [90, 180]))
                {
                    $score += 7;
                }// tr日火/火日/火月合拱六分各+5
                elseif (in_array($tr_planet1[4]['phase']['4-1']['phase_e'], [60, 120]))
                {
                    $score += 5;
                }
            }
        }
        // tr水火或火水刑冲+6
        if ((isset($tr_planet1[2]['phase']['2-4'])
                && in_array($tr_planet1[2]['phase']['2-4']['phase_e'], [90, 180]))
            || (isset($tr_planet1[4]['phase']['4-2'])
                && in_array($tr_planet1[4]['phase']['4-2']['phase_e'], [90, 180])))
        {
            $score += 6;
        }
        $level = $this->modLevel5(floor($score / 10));

        if ($level >= 1)
        {
            $temp = [
                'flag' => '5-5',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        //  像一道闪电路过你身边
        // 20181223 像一道闪电路过你身边 条件中的 主宫 改为 只有7
        //      主宫7/11
        //      主星金
        //      天王的影响力大于10且为最大
        // 改为15
        $score = 0;
        /**
         * relation 影响值
         * destory 破坏值
         * achievement 成就值
         */
        $planet3 = $CaclByTopic->init($source, ['target' => 3, 'house' => [7], 'planet' => 3]);
        $planet4 = $CaclByTopic->init($source, ['target' => 4, 'house' => [7], 'planet' => 3]);
        $planet5 = $CaclByTopic->init($source, ['target' => 5, 'house' => [7], 'planet' => 3]);
        $planet6 = $CaclByTopic->init($source, ['target' => 6, 'house' => [7], 'planet' => 3]);
        $planet7 = $CaclByTopic->init($source, ['target' => 7, 'house' => [7], 'planet' => 3]);
        $planet8 = $CaclByTopic->init($source, ['target' => 8, 'house' => [7], 'planet' => 3]);
        $planet9 = $CaclByTopic->init($source, ['target' => 9, 'house' => [7], 'planet' => 3]);

        $relations = [$planet3['relation'], $planet4['relation'], $planet5['relation'], $planet6['relation'], $planet7['relation'], $planet8['relation'], $planet9['relation']];

        if ($planet7['relation'] >= 15 && $planet7['relation'] == max($relations))
        {
            $score = $planet7['relation'];

            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '5-6',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        //  TODO 职场如战场
        //      这一阶段的你，特别容易在工作中产生人际上的困扰，可能与团队成员配合不够默契、分歧较多，也可能碰上猪队友扯你的后腿，甚至可能遭遇小人或是不良竞争，跟你明争暗斗，或是逼你站队，搅得整个团队乌烟瘴气。有时这些来自于你与上司的关系不睦或与合作方不合，总之理清工作上的关系可能需要费一翻手脚。
        //          海冥是第一层流星，火土是第二层，天王是助星
        //          日金水是一级引动星，月亮是二级引动星
        //          主宫位是10/11
        //          副宫位是1/7
        //          标靶星日月金命（tp计算去掉月亮）
        //          征象星金星
        //          tr
        //              一层星在主宫位刑冲标靶星+5（标靶不重复计算，流星重复，其余均遵守此原则）
        //                  二层星在主宫合拱六分标靶星+5
        //                      一级引动星与火土海刑冲+10
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                      一级引动星与火土海冥合拱六分+5
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                  二层星合拱六分主宫位的标靶星+5
        //                      一级引动星与火土海刑冲+10
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                      一级引动星与火土海冥合拱六分+5
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //              一层星刑冲主宫位的标靶星+5
        //                  二层星在主宫合拱六分标靶星+5
        //                      一级引动星与火土海刑冲+10
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                      一级引动星与火土海冥合拱六分+5
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                  二层星合拱六分主宫位的标靶星+5
        //                      一级引动星与火土海刑冲+10
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //                      一级引动星与火土海冥合拱六分+5
        //                          若火土海冥或引动星在主宫/副宫+5
        //                          二级引动星与火土海冥刑冲+5
        //                              若二级星或火土海冥在主副宫+3
        //                          二级引动星与火土海冥合拱六分+3
        //                              若二级星或火土海冥在主副宫+3
        //              二层星刑冲主宫位的标靶星+5
        //                  一级引动星与火土海刑冲+10
        //                      若火土海冥或引动星在主宫/副宫+5
        //                      二级引动星与火土海冥刑冲+5
        //                          若二级星或火土海冥在主副宫+3
        //                      二级引动星与火土海冥合拱六分+3
        //                          若二级星或火土海冥在主副宫+3
        //                  一级引动星与火土海冥合拱六分+5
        //                      若火土海冥或引动星在主宫/副宫+5
        //                      二级引动星与火土海冥刑冲+5
        //                          若二级星或火土海冥在主副宫+3
        //                      二级引动星与火土海冥合拱六分+3
        //                          若二级星或火土海冥在主副宫+3
        //                  一级引动星与火土海刑冲+10
        //                      若火土海冥或引动星在主宫/副宫+5
        //                      二级引动星与火土海冥刑冲+5
        //                          若二级星或火土海冥在主副宫+3
        //                      二级引动星与火土海冥合拱六分+3
        //                          若二级星或火土海冥在主副宫+3
        //                  一级引动星与火土海冥合拱六分+5
        //                      若火土海冥或引动星在主宫/副宫+5
        //                      二级引动星与火土海冥刑冲+5
        //                          若二级星或火土海冥在主副宫+3
        //                      二级引动星与火土海冥合拱六分+3
        //                          若二级星或火土海冥在主副宫+3
        //          征象星
        //              本命中，征象星被一二层星刑冲，或被一二层星所夹（位于两星中间并合），或与一二层星三颗或以上成相，+1
        //                  刑冲或征象星位于主宫副宫+5
        //                  tr一层二层流星与本命征象星合刑冲+10
        //                  tr一层二层流星与本命征象星拱六分+5
        //              tr一层二层流星与本命征象星合刑冲+10
        //              tr一层二层流星与本命征象星拱六分+5
        //              tp征象星与一二层星刑冲+5，合拱六分+2
        //          tp
        //              tp主宫内有一二层星刑冲标靶星，或主宫内有标靶星被一二层星刑冲+5（其它与主宫相关的任意刑冲+2，若其中包含标靶星或一二层星再+1）
        //                  此时月亮不在刑冲中，并与该刑冲结构中某星刑冲+5（每有一个加一次），合+3，拱六分+2
        //          征象星有分数时，每10分1星，tp+tr+征象星分数得出最终星级；征象星无分数时，25分为1星
        //      这是合作为王的时代，所以团队和谐非常重要。遇到这些情形一定要保持冷静，不要有太多情绪，负面情绪的爆发会进一步伤害工作关系，也不要向同事抱怨，哪怕是私下里，也可能带来许多麻烦，弄巧成拙就不好了。需要自己消化的请自己努力消化，然后尽力弄清楚到底问题出在哪儿，有多严重，然后考虑如何对症下药。
        //这是考验职场情商智商的大好机会，一大把经验值等着你去赚，不要遇到困难就想逃。
        //  TODO 办公室有个小天使
        //
        //这一时期你会拥有良好的职场关系，较容易得到信任，提拔，甚至出现贵人也说不定。也可能是合作关系比较理想，或在职场中有良好的桃花。不管怎样，你的职场生活大体是愉悦的，很可能取得不错的收获，偶尔有点小风浪，都不会动摇你的根基。
        //
        //（如果同一时期，也存在“职场如战场”这一主题，往往是危机与机遇并存，收获与损失交替，看你能否好好把握。）
        //          征象星金星
        //          成就星金木（木一层，金二层）
        //          破坏星火星土星海王冥王
        //          标靶星日月金水命
        //          tr引动星日水月
        //          主宫10/11
        //          tp
        //              主宫内有星成合拱六分，一方为成就星一方为标靶星+5（如标靶为月亮+10）
        //              主宫内有星对冲，一方为成就星一方为标靶星，且无破坏星与双方刑冲+4（如标靶为月亮+8）
        //              若主宫内有星形成刑冲
        //                  标靶与破坏
        //                      -5
        //                  成就与破坏
        //                      -4
        //                  破坏与破坏
        //                      -5
        //                  破坏与其它
        //                      -4
        //                  标靶与其它
        //                      -3
        //          tr
        //              一层成就星与主宫内标靶星冲合拱六分，或，一层成就星在主宫内与标靶星冲合拱六分+5
        //                  二层成就星与主宫内标靶星冲合拱六分，或二层成就星在主宫内与标靶星冲合拱六分+5
        //                  引动星与主宫内标靶星冲合拱六分，或引动星在主宫内与标靶星冲合拱六分+4
        //          象征星
        //              本命象征星与成就星拱合六分，或标靶星与成就星成拱合六分+1
        //                  该相位关联主宫+4
        //                  tr成就星与该相位星之一合相+10
        //              tr成就星与本命征象星冲合+5
        //              tr成就星与本命征象星拱六分+3
        //              tp征象星与成就星冲合拱六分+5
        //              tp征象星与月亮冲合拱六分+5
        //          征象星有分数时，每10分1星，tp+tr+征象星分数得出最终星级；征象星无分数时，25分为1星
        //      人际关系良好，可谓难得的职场机遇期，一定要努力工作，不宜偷懒。

        return $result;
    }

    /**
     * 心情主题
     * @param array $source
     * @return array
     */
    public function getMoodTopic($source = [])
    {
        $result = [];

        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘

        $p1_phase4689_num = 0;
        $p1_phase46789_num = 0;
        $p1_phase4689_090180_num = 0;
        $p1_phase4689_90180_num = 0;
        $p1_phase46789_90180_num = 0;
        $p1_phase35_num = 0;
        $p1_phase_90180_num = 0;
        $p1_phase35_90180_num = 0;
        $p1_phase4789_090180_num = 0;
        $p1_phase789_090180_num = 0;
        $p1_phase4789_num = 0;
        $p1_phase4_e = -1;
        $p1_phase5_e = -1;
        $p1_phase6_e = -1;
        $p1_phase7_e = -1;
        $p1_phase8_e = -1;
        $p1_phase9_e = -1;
        $p1_in_t_square = false;
        $p1_phase_house71112_90180_num = 0;
//        $p1_phase_house71112_60120_p_phase_90180_num2 = false;

        if (!empty($tp_planet[1]['phase']))
        {
            foreach ($tp_planet[1]['phase'] as $phase)
            {
                if (in_array($phase['id'], [4, 6, 8, 9]))
                {
                    $p1_phase4689_num++;
                    if (in_array($phase['phase_e'], [0, 90, 180]))
                    {
                        $p1_phase4689_090180_num++;
                    }
                    if (in_array($phase['phase_e'], [90, 180]))
                    {
                        $p1_phase4689_90180_num++;
                    }
                } elseif (in_array($phase['id'], [3, 5]))
                {
                    $p1_phase35_num++;
                }
                if (in_array($phase['phase_e'], [90, 180]))
                {
                    $p1_phase_90180_num++;
                } else
                {
                    if (in_array($phase['id'], [3, 5]))
                    {
                        $p1_phase35_90180_num++;
                    }
                }
                if (in_array($phase['phase_e'], [0, 90, 180]))
                {
                    if (in_array($phase['id'], [7, 8, 9]))
                    {
                        $p1_phase789_090180_num++;
                    }
                    if (in_array($phase['id'], [4, 7, 8, 9]))
                    {
                        $p1_phase4789_090180_num++;
                    }

                }
                if ($phase['id'] == 4)
                {
                    $p1_phase4_e = $phase['phase_e'];
                }
                if ($phase['id'] == 5)
                {
                    $p1_phase5_e = $phase['phase_e'];
                }
                if ($phase['id'] == 6)
                {
                    $p1_phase6_e = $phase['phase_e'];
                }
                if ($phase['id'] == 7)
                {
                    $p1_phase7_e = $phase['phase_e'];
                }
                if ($phase['id'] == 8)
                {
                    $p1_phase8_e = $phase['phase_e'];
                }
                if ($phase['id'] == 9)
                {
                    $p1_phase9_e = $phase['phase_e'];
                }
                if (in_array($phase['id'], [4, 7, 8, 9]))
                {
                    $p1_phase4789_num++;
                }
                if (in_array($phase['id'], [4, 6, 7, 8, 9]))
                {
                    if (in_array($phase['phase_e'], [90, 180]))
                    {
                        $p1_phase46789_90180_num++;
                    }
                    $p1_phase46789_num++;
                }
                if (in_array($phase['phase_e'], [60, 120])
                    && in_array($tp_planet[$phase['id']]['in_house_id'], [7, 11, 12]))
                {
                    $phase_90180_num = 0;
                    foreach ($tp_planet[$phase['id']]['phase'] as $ps)
                    {
                        if (in_array($ps['phase_e'], [90, 180]))
                        {
                            $phase_90180_num++;
                        }
                    }
//                    if ($phase_90180_num >= 2)
//                    {
//                        $p1_phase_house71112_60120_p_phase_90180_num2 = true;
//                    }
                }
                if (in_array($phase['phase_e'], [90, 180])
                    && in_array($tp_planet[$phase['id']]['in_house_id'], [7, 11, 12]))
                {
                    $p1_phase_house71112_90180_num++;
                }
            }
        }
        if (!empty($source['thirdprogressed_data']['t_square']))
        {
            foreach ($source['thirdprogressed_data']['t_square'] as $t_square)
            {
                if (in_array(1, [$t_square]))
                {
                    $p1_in_t_square = true;
                }
            }
        }

        //运势高低（只论三限，满足条件就是1星）
        //  吉祥如意心情好（开心时间）
        //      三限月亮不与火土海冥成相且至少与金木之一成相且无刑冲
        //      三限月亮不与火土海冥成相且与金木之一成冲相位且月亮不在6/8/12
        $level = 0;
        if ($p1_phase4689_num <= 0 && $p1_phase35_num >= 1 && $p1_phase_90180_num <= 0)
        {
            $level++;
        }
        if ($p1_phase4689_num <= 0 && $p1_phase35_90180_num >= 1 && !in_array($tp_planet[1]['in_house_id'], [6, 8, 12]))
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-1',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  发奋时间
        //      月火合拱六分，且月火都不在8/12宫，且月亮不与天海冥合刑冲
        $level = 0;
        if ($p1_phase789_090180_num <= 0 && in_array($p1_phase4_e, [0, 60, 120])
            && !in_array($tp_planet[1]['in_house_id'], [8, 12]) && !in_array($tp_planet[4]['in_house_id'], [8, 12]))
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-2',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  破坏时间
        //      月火刑
        $level = 0;
        if ($p1_phase4_e == 90)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-3',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  专注时间
        //      月土拱六分，且月亮不与火天海冥合刑冲
        //      月土合刑冲，且月亮不在6/8/12，且月亮不与火天海冥成相
        $level = 0;
        if (in_array($p1_phase6_e, [60, 120]) && $p1_phase4789_090180_num <= 0)
        {
            $level++;
        } elseif (in_array($p1_phase6_e, [0, 90, 180]) && !in_array($tp_planet[1]['in_house_id'], [6, 8, 12])
            && $p1_phase4789_num <= 0)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-4',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  动荡时间
        //      月天刑冲合
        //      月天拱六分，同时与任意星刑冲
        $level = 0;
        if (in_array($p1_phase7_e, [0, 90, 180]))
        {
            $level++;
        } elseif (in_array($p1_phase7_e, [60, 120]) && $p1_phase_90180_num >= 1)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-5',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  迷幻时间
        //      月海刑冲合
        //      月海拱六分，同时与任意星刑冲
        $level = 0;
        if (in_array($p1_phase8_e, [0, 90, 180]))
        {
            $level++;
        } elseif (in_array($p1_phase8_e, [60, 120]) && $p1_phase_90180_num >= 1)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-6',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  反思时间
        //      月冥刑冲合
        //      月冥拱六分，同时与任意星刑冲
        $level = 0;
        if (in_array($p1_phase9_e, [0, 90, 180]))
        {
            $level++;
        } elseif (in_array($p1_phase9_e, [60, 120]) && $p1_phase_90180_num >= 1)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-7',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  复合时间
        //      金冥刑冲，且月亮与金星成相或过5/7宫与木星成相或与5/7宫木星成相
        $level = 0;
        if (
            (isset($tp_planet[3]['phase']['3-9']) && in_array($tp_planet[3]['phase']['3-9']['phase_e'], [90, 180]))
            && (isset($tp_planet[1]['phase']['1-3']) || (isset($tp_planet[1]['phase']['1-5'])
                    && (in_array($tp_planet[1]['in_house_id'], [5, 7])
                        || in_array($tp_planet[5]['in_house_id'], [5, 7])))))
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-8',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  警戒时间
        //      月亮受火土冥海合刑冲两次或两次以上
        //      月亮在6/8/12宫刑冲火土冥海之一
        //      月亮与火土天海冥之一刑冲并参与T三角
        $level = 0;
        if ($p1_phase4689_090180_num >= 2)
        {
            $level++;
        }
        if (in_array($tp_planet[1]['in_house_id'], [6, 8, 12]) && $p1_phase4689_90180_num >= 1)
        {
            $level++;
        }
        if ($p1_phase46789_90180_num >= 1 && $p1_in_t_square)
        {
            $level++;
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-9',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  低迷时间
        //      月亮在6/8/12宫被火土海冥之一刑冲，太阳也被火土海冥之一刑冲，且金木不合轴并对日月金水均无相位
        //      月亮在6/8/12宫与火土海冥之一刑冲，且与火土天海冥至少三个成相位，且月亮不与木星合拱六分
        $level = 0;
        if ($p1_phase46789_90180_num > 0)
        {
            if (
                (
                    (isset($tp_planet[0]['phase']['0-4'])
                        && in_array($tp_planet[0]['phase']['0-4']['phase_e'], [90, 180]))
                    || (isset($tp_planet[0]['phase']['0-6'])
                        && in_array($tp_planet[0]['phase']['0-6']['phase_e'], [90, 180]))
                    || (isset($tp_planet[0]['phase']['0-8'])
                        && in_array($tp_planet[0]['phase']['0-8']['phase_e'], [90, 180]))
                    || (isset($tp_planet[0]['phase']['0-9'])
                        && in_array($tp_planet[0]['phase']['0-9']['phase_e'], [90, 180]))
                )
                &&
                (
                    !isset($tp_planet[3]['phase']['3-' . ASC])
                    || !in_array($tp_planet[3]['phase']['3-' . ASC]['phase_e'], [0, 180])
                )
                &&
                (
                    !isset($tp_planet[3]['phase']['3-' . MC])
                    || !in_array($tp_planet[3]['phase']['3-' . MC]['phase_e'], [0, 180])
                )
                &&
                (
                    !isset($tp_planet[5]['phase']['5-' . ASC])
                    || !in_array($tp_planet[5]['phase']['5-' . ASC]['phase_e'], [0, 180])
                )
                &&
                (
                    !isset($tp_planet[5]['phase']['5-' . MC])
                    || !in_array($tp_planet[5]['phase']['5-' . MC]['phase_e'], [0, 180])
                )
                && !isset($tp_planet[3]['phase']['3-0'])
                && !isset($tp_planet[3]['phase']['3-1'])
                && !isset($tp_planet[3]['phase']['3-2'])
                && !isset($tp_planet[5]['phase']['5-0'])
                && !isset($tp_planet[5]['phase']['5-1'])
                && !isset($tp_planet[5]['phase']['5-3'])
                && !isset($tp_planet[5]['phase']['5-2'])
            )
            {
                $level++;
            }
            if ($p1_phase46789_num >= 3 && !in_array($p1_phase5_e, [0, 60, 120]))
            {
                $level++;
            }
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-10',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  流言时间 => 魅惑时间
        //      水海刑冲，月亮与其中之一成相 =》火海
        //      水海合拱六分，月亮与其中之一刑冲 =》 火海
        //      以上两者之一成立，且月亮在7/11/12宫+1星；以上两者之一成立，且月亮与7/11/12宫星体刑冲+1星；以上两者之一成立，且月亮与7/11/12宫星体拱六分，且该星体受到两次以上刑冲+1星
//        $level = 0;
//        if (isset($tp_planet[4]['phase']['4-8']) && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [90, 180])
//            && (isset($tp_planet[1]['phase']['1-2']) || isset($tp_planet[1]['phase']['1-8'])))
//        {
//            $level++;
//        } elseif (isset($tp_planet[2]['phase']['2-8'])
//            && in_array($tp_planet[4]['phase']['4-8']['phase_e'], [0, 60, 120])
//            && ((isset($tp_planet[1]['phase']['1-2'])
//                    && in_array($tp_planet[1]['phase']['1-2']['phase_e'], [90, 180]))
//                || (isset($tp_planet[1]['phase']['1-8'])
//                    && in_array($tp_planet[1]['phase']['1-8']['phase_e'], [90, 180]))))
//        {
//            $level++;
//        }
//        if ($level > 0)
//        {
//            if (in_array($tp_planet[1]['in_house_id'], [7, 11, 12]))
//            {
//                $level++;
//            }
//            if ($p1_phase_house71112_90180_num >= 1)
//            {
//                $level++;
//            }
//            if ($p1_phase_house71112_60120_p_phase_90180_num2)
//            {
//                $level++;
//            }
//        }
//        if ($level > 0)
//        {
//            $temp = [
//                'flag' => '6-11',
//                'level' => $level,
//            ];
//            $result[] = $temp;
//        }
        //  魅力时间
        //      月金成非刑相，且，月金都不与土冥成相
        //          此时月金之一位于1/5/7/11+1星
        $level = 0;
        if (isset($tp_planet[1]['phase']['1-3']) && $tp_planet[1]['phase']['1-3']['phase_e'] != 90
            && !isset($tp_planet[1]['phase']['1-6']) && !isset($tp_planet[1]['phase']['1-9'])
            && !isset($tp_planet[3]['phase']['3-6']) && !isset($tp_planet[3]['phase']['3-9']))
        {
            $level++;
            if (in_array($tp_planet[1]['in_house_id'], [1, 5, 7, 11])
                || in_array($tp_planet[3]['in_house_id'], [1, 5, 7, 11]))
            {
                $level++;
            }
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-12',
                'level' => $level,
            ];
            $result[] = $temp;
        }
        //  机遇时间
        //      月木成非刑相，且，月木之一在6/10宫或月亮同时与10宫的日金火成合拱六分
        //          此时有日木相位+1星
        $level = 0;
        if ($p1_phase5_e != 90
            && (in_array($tp_planet[1]['in_house_id'], [6, 10]) || in_array($tp_planet[5]['in_house_id'], [6, 10]))
            &&
            (
                ($tp_planet[0]['in_house_id'] == 10
                    && isset($tp_planet[1]['phase']['1-0'])
                    && in_array($tp_planet[1]['phase']['1-0']['phase_e'], [0, 60, 120]))
                ||
                ($tp_planet[3]['in_house_id'] == 10
                    && isset($tp_planet[1]['phase']['1-3'])
                    && in_array($tp_planet[1]['phase']['1-3']['phase_e'], [0, 60, 120]))
                ||
                ($tp_planet[4]['in_house_id'] == 10
                    && isset($tp_planet[1]['phase']['1-4'])
                    && in_array($tp_planet[1]['phase']['1-4']['phase_e'], [0, 60, 120]))
            )
        )
        {
            $level++;
            if (isset($tp_planet[0]['phase']['0-5']))
            {
                $level++;
            }
        }
        if ($level > 0)
        {
            $temp = [
                'flag' => '6-13',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        return $result;
    }

    /**
     * 出行主题
     * @param array $source
     * @return array
     */
    public function getTravelTopic($source = [])
    {
        $result = [];

        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        //出行
        // 出门见喜
        $score = $score1 = $score2 = 0;
        //动星
        // 月亮与水星成非刑相+5
        if (isset($tp_planet[1]['phase']['1-2']) && $tp_planet[1]['phase']['1-2']['phase_e'] != 90)
        {
            $score1 += 5;
        }
        // 水星合轴或合太阳，且月亮与木星或天王成相+5
        if ((
                (isset($tp_planet[2]['phase']['2-0']) && $tp_planet[2]['phase']['2-0']['phase_e'] == 0)
                || (isset($tp_planet[2]['phase']['2-' . ASC]) && in_array($tp_planet[2]['phase']['2-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[2]['phase']['2-' . MC]) && in_array($tp_planet[2]['phase']['2-' . MC]['phase_e'], [0, 180])))
            && (isset($tp_planet[1]['phase']['1-5']) || isset($tp_planet[1]['phase']['1-7'])))
        {
            $score1 += 5;
        }
        // 月亮过3、9宫与木星或天王星成相+5
        if ((in_array($tp_planet[1]['in_house_id'], [3, 9]))
            && (isset($tp_planet[1]['phase']['1-5']) || isset($tp_planet[1]['phase']['1-7']))
        )
        {
            $score1 += 5;
        }
        // 水星与木星成相
        if (isset($tp_planet[2]['phase']['2-5']))
        {
            $score1 += 5;
        }
        //喜星
        //  月亮与金星成非刑相+5
        if (isset($tp_planet[1]['phase']['1-3']) && $tp_planet[1]['phase']['1-3']['phase_e'] != 90)
        {
            $score2 += 5;
        }
        //  金星合轴且无金土刑冲合相+5
        if (((isset($tp_planet[3]['phase']['3-' . ASC]) && in_array($tp_planet[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[3]['phase']['3-' . MC]) && in_array($tp_planet[3]['phase']['3-' . MC]['phase_e'], [0, 180])))
            && (!isset($tp_planet[3]['phase']['3-6']) || !in_array($tp_planet[3]['phase']['3-6']['phase_e'], [0, 90, 180])))
        {
            $score2 += 5;
        }
        //  日金合+5
        if (isset($tp_planet[0]['phase']['0-3']) && $tp_planet[0]['phase']['0-3']['phase_e'] == 0)
        {
            $score2 += 5;
        }
        //  金土刑冲-20
        if (isset($tp_planet[3]['phase']['3-6']) && in_array($tp_planet[3]['phase']['3-6']['phase_e'], [90, 180]))
        {
            $score2 += -20;
        }
        if ($score1 > 0 && $score2 > 0 && $score1 + $score2 >= 10)
        {
            $score = $score1 + $score2;

            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '7-1',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }
        // 不如归去
        $score = 0;
        // tp月亮过4宫或月亮合天底+5
        if ($tp_planet[1]['in_house_id'] == 4 || (isset($tp_planet[1]['phase']['1-' . ASC])
                && $tp_planet[1]['phase']['1-' . ASC]['phase_e'] == 180))
        {
            $score += 5;
            if (!empty($tp_planet[1]['phase']))
            {
                foreach ($tp_planet[1]['phase'] as $phase)
                {
                    if ($phase['id'] == 2 && $phase['phase_e'] != 90)
                    {
                        $is_p1_phase2_no90 = true;
                    }
                }
            }
            // 月亮与水星成非刑相+5
            if (isset($tp_planet[1]['phase']['1-2']) && $tp_planet[1]['phase']['1-2']['phase_e'] != 90)
            {
                $score += 5;
            }
            // 月亮与日金火木中的两个成相+5
            $p1_phase0345_num = 0;
            if (!empty($tp_planet[1]['phase']))
            {
                foreach ($tp_planet[1]['phase'] as $phase)
                {
                    if (in_array($phase['id'], [0, 3, 4, 5])) $p1_phase0345_num++;
                }
            }
            if ($p1_phase0345_num >= 2)
            {
                $score += 5;
            }
            // tr流水或流火与本水成相+5
            if (isset($tr_planet1[2]['phase']['2-2']) || isset($tr_planet1[4]['phase']['4-2']))
            {
                $score += 5;
            }
            // tr流水或流火与本命3/9宫的日月金木成相+5
            if ((in_array($tr_planet2[0]['in_house_id'], [3, 9]) && isset($tr_planet1[2]['phase']['2-0']))
                || (in_array($tr_planet2[1]['in_house_id'], [3, 9]) && isset($tr_planet1[2]['phase']['2-1']))
                || (in_array($tr_planet2[3]['in_house_id'], [3, 9]) && isset($tr_planet1[2]['phase']['2-3']))
                || (in_array($tr_planet2[5]['in_house_id'], [3, 9]) && isset($tr_planet1[2]['phase']['2-5'])))
            {
                $score += 5;
            }
            if ((in_array($tr_planet2[0]['in_house_id'], [3, 9]) && isset($tr_planet1[4]['phase']['4-0']))
                || (in_array($tr_planet2[1]['in_house_id'], [3, 9]) && isset($tr_planet1[4]['phase']['4-1']))
                || (in_array($tr_planet2[3]['in_house_id'], [3, 9]) && isset($tr_planet1[4]['phase']['4-3']))
                || (in_array($tr_planet2[5]['in_house_id'], [3, 9]) && isset($tr_planet1[4]['phase']['4-5'])))
            {
                $score += 5;
            }
        }
        $level = $this->modLevel5(floor($score / 10));

        if ($level >= 1)
        {
            $temp = [
                'flag' => '7-2',
                'level' => $level,
            ];
            $result[] = $temp;
        }

        // 树挪死，人挪活
        $score = 0;
        //  tp日木天同时成相+10
        //      太阳在3/9宫或木星在3/9宫+10
        //      太阳或木或天合轴+10
        if (isset($tp_planet[0]['phase']['0-5']) && isset($tp_planet[0]['phase']['0-7']) && isset($tp_planet[5]['phase']['5-7']))
        {
            $score += 10;
            if (in_array($tp_planet[0]['in_house_id'], [3, 9]) || in_array($tp_planet[5]['in_house_id'], [3, 9]))
            {
                $score += 10;
            }
            if ((isset($tp_planet[0]['phase']['0-' . ASC]) && in_array($tp_planet[0]['phase']['0-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[0]['phase']['0-' . MC]) && in_array($tp_planet[0]['phase']['0-' . MC]['phase_e'], [0, 180]))
                || (isset($tp_planet[5]['phase']['5-' . ASC]) && in_array($tp_planet[5]['phase']['5-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[5]['phase']['5-' . MC]) && in_array($tp_planet[5]['phase']['5-' . MC]['phase_e'], [0, 180]))
                || (isset($tp_planet[7]['phase']['7-' . ASC]) && in_array($tp_planet[7]['phase']['7-' . ASC]['phase_e'], [0, 180]))
                || (isset($tp_planet[7]['phase']['7-' . MC]) && in_array($tp_planet[7]['phase']['7-' . MC]['phase_e'], [0, 180])))
            {
                $score += 10;
            }
        }
        //  tp水木天或火木天或金木天形成二冲一+5
        $base_num = 0;
        $status = [
            5 => 0,
            7 => 0,
        ];
        // 木冲天
        if (isset($tp_planet[5]['phase']['5-7']) && $tp_planet[5]['phase']['5-7']['phase_e'] == 180)
        {
            $base_num++;
            $status[5]++;
            $status[7]++;
        }
        $sus = [];
        foreach ([2, 3, 4] as $p1)
        {
            $temp = $base_num;
            // 冲木
            if (isset($tp_planet[$p1]['phase'][$p1 . '-5']) && $tp_planet[$p1]['phase'][$p1 . '-5']['phase_e'] == 180)
            {
                $temp++;
                $status[5]++;
                if (!isset($status[$p1])) $status[$p1] = 1; else $status[$p1]++;
            }
            // 冲天
            if (isset($tp_planet[$p1]['phase'][$p1 . '-7']) && $tp_planet[$p1]['phase'][$p1 . '-7']['phase_e'] == 180)
            {
                $temp++;
                $status[7]++;
                if (!isset($status[$p1])) $status[$p1] = 1; else $status[$p1]++;
            }
            // 形成二冲一
            $score_temp = 0;
            if ($temp >= 2)
            {
                $score_temp += 5;
                foreach ($status as $k => $s)
                {
                    // 非同时被两星冲的星体
                    if ($s <= 1)
                    {
                        // 冲相合轴+5
                        if ((isset($tp_planet[$k]['phase'][$k . '-' . ASC])
                                && in_array($tp_planet[$k]['phase'][$k . '-' . ASC]['phase_e'], [0, 180]))
                            || (isset($tp_planet[$k]['phase'][$k . '-' . MC])
                                && in_array($tp_planet[$k]['phase'][$k . '-' . MC]['phase_e'], [0, 180])))
                        {
                            $score_temp += 5;
                        }
                        // 冲相在3-9宫+5
                        if (in_array($tp_planet[$k]['in_house_id'], [3, 4, 5, 6, 7, 8, 9]))
                        {
                            $score_temp += 5;
                        }
                    }
                }
                if ($score_temp > 0)
                {
                    $sus[] = $score_temp;
                }
            }
        }
        if (!empty($sus))
        {
            $score += max($sus);
        }

        //  以上得分过10 时，月木合+10，月木成非合相+5
        if ($score >= 10)
        {
            if (isset($tp_planet[1]['phase']['1-5']))
            {
                if (in_array($tp_planet[1]['phase']['1-5']['phase_e'], [0]))
                {
                    $score += 10;
                } else
                {
                    $score += 5;
                }
            }
            $level = $this->modLevel5(floor($score / 10));

            if ($level >= 1)
            {
                $temp = [
                    'flag' => '7-3',
                    'level' => $level,
                ];
                $result[] = $temp;
            }
        }

        // TODO 平安大于一切 1星基础分改为12，每6分加1星
        // 这一时期较容易出现磕磕绊绊、割伤烫伤、小碰撞、小摩擦，注意的话就会小事化无，不注意也可能小事变大。口角、是非不快也常有发生，你很可能变得易怒而且冲动。内心焦虑躁动，不经意间出口伤人。尤其要注意出行中的各种不顺与意外，当然也可能仅仅是一些小事搅得心情不佳。
        // 3/9宫不良
        //  3/9宫内有行星对冲+5
        //  3/9宫内行星被刑克+5
        //  月亮参与3、9、12宫的T三角+10
        //  tp月亮过3、9、12宫，与火土天海冥之一成相+5
        // tp火星与土、天、海、冥之一成相+3
        // tp日天成相+3
        // tp日火成相+3
        // tp月亮与火土天冥之一成相+3
        // 水星
        //  水火刑冲+5
        //  水天刑冲+5
        //  水冥刑冲+5
        //  水海刑冲+5
        // 12宫
        //  12宫内有火星或天王、冥王与3/9宫内星成相+5
        //

        return $result;
    }

    /**
     * 保证主题级别 在 0-5之间
     * @param int $level
     * @return int
     */
    private function modLevel5($level = 0)
    {
        return $level > 5 ? 5 : ($level < 0 ? 0 : intval($level));
    }


}
